Bouland and Aaronson, Equation (26)

Percentage Accurate: 99.9% → 100.0%
Time: 6.1s
Alternatives: 9
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 9 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) \]
    6. unpow199.9%

      \[\leadsto \left(\color{blue}{{\left(a \cdot a + b \cdot b\right)}^{1}} \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) \]
    7. sqr-pow99.9%

      \[\leadsto \left(\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(\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) \]
    8. unpow3100.0%

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

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

      \[\leadsto {\left({\left(a \cdot a + b \cdot b\right)}^{\color{blue}{0.5}}\right)}^{\left(3 + 1\right)} + \left(4 \cdot \left(b \cdot b\right) - 1\right) \]
    11. unpow1/2100.0%

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

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

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

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

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

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

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

Alternative 2: 99.9% accurate, 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 3: 93.5% accurate, 1.0× speedup?

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

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

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


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

    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) \]
      6. unpow199.9%

        \[\leadsto \left(\color{blue}{{\left(a \cdot a + b \cdot b\right)}^{1}} \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) \]
      7. sqr-pow99.9%

        \[\leadsto \left(\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(\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) \]
      8. unpow3100.0%

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

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

        \[\leadsto {\left({\left(a \cdot a + b \cdot b\right)}^{\color{blue}{0.5}}\right)}^{\left(3 + 1\right)} + \left(4 \cdot \left(b \cdot b\right) - 1\right) \]
      11. unpow1/2100.0%

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

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

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

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

        \[\leadsto {\left(\mathsf{hypot}\left(a, b\right)\right)}^{4} + \left(\color{blue}{b \cdot \left(4 \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 100.0%

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

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

    if 4.00000000000000022e-32 < (*.f64 b b)

    1. Initial program 99.9%

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

        \[\leadsto \left(\color{blue}{{\left(a \cdot a + b \cdot b\right)}^{1}} \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) \]
      7. sqr-pow99.9%

        \[\leadsto \left(\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(\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) \]
      8. unpow399.9%

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

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

        \[\leadsto {\left({\left(a \cdot a + b \cdot b\right)}^{\color{blue}{0.5}}\right)}^{\left(3 + 1\right)} + \left(4 \cdot \left(b \cdot b\right) - 1\right) \]
      11. unpow1/2100.0%

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

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

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

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

        \[\leadsto {\left(\mathsf{hypot}\left(a, b\right)\right)}^{4} + \left(\color{blue}{b \cdot \left(4 \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. Step-by-step derivation
      1. hypot-udef100.0%

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

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

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

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

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

        \[\leadsto \color{blue}{\left(\left(a \cdot a + b \cdot b\right) \cdot \left(b \cdot b\right) + \left(a \cdot a + b \cdot b\right) \cdot \left(a \cdot a\right)\right)} + \mathsf{fma}\left(b, b \cdot 4, -1\right) \]
      7. add-sqr-sqrt87.5%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left({\left(\mathsf{hypot}\left(a, b\right) \cdot b\right)}^{2} + {\left(\mathsf{hypot}\left(a, b\right)\right)}^{2} \cdot \color{blue}{{a}^{2}}\right) + \mathsf{fma}\left(b, b \cdot 4, -1\right) \]
      18. pow-prod-down99.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 94.6% accurate, 1.0× speedup?

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

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

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


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

    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) \]
      6. unpow199.9%

        \[\leadsto \left(\color{blue}{{\left(a \cdot a + b \cdot b\right)}^{1}} \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) \]
      7. sqr-pow99.9%

        \[\leadsto \left(\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(\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) \]
      8. unpow3100.0%

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

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

        \[\leadsto {\left({\left(a \cdot a + b \cdot b\right)}^{\color{blue}{0.5}}\right)}^{\left(3 + 1\right)} + \left(4 \cdot \left(b \cdot b\right) - 1\right) \]
      11. unpow1/2100.0%

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

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

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

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

        \[\leadsto {\left(\mathsf{hypot}\left(a, b\right)\right)}^{4} + \left(\color{blue}{b \cdot \left(4 \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 99.1%

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

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

    if 5e3 < (*.f64 b b)

    1. Initial program 99.9%

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

        \[\leadsto \left(\color{blue}{{\left(a \cdot a + b \cdot b\right)}^{1}} \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) \]
      7. sqr-pow99.9%

        \[\leadsto \left(\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(\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) \]
      8. unpow399.9%

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

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

        \[\leadsto {\left({\left(a \cdot a + b \cdot b\right)}^{\color{blue}{0.5}}\right)}^{\left(3 + 1\right)} + \left(4 \cdot \left(b \cdot b\right) - 1\right) \]
      11. unpow1/2100.0%

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

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

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

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

        \[\leadsto {\left(\mathsf{hypot}\left(a, b\right)\right)}^{4} + \left(\color{blue}{b \cdot \left(4 \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 0 93.0%

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

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

        \[\leadsto \color{blue}{{b}^{2} \cdot 4} + {b}^{4} \]
      2. unpow293.0%

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

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(b, b \cdot 4, {b}^{4}\right)} \]
    7. Simplified93.0%

      \[\leadsto \color{blue}{\mathsf{fma}\left(b, b \cdot 4, {b}^{4}\right)} \]
    8. Step-by-step derivation
      1. fma-udef93.0%

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

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

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

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

Alternative 5: 94.4% accurate, 1.1× speedup?

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

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

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


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

    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) \]
      6. unpow199.9%

        \[\leadsto \left(\color{blue}{{\left(a \cdot a + b \cdot b\right)}^{1}} \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) \]
      7. sqr-pow99.9%

        \[\leadsto \left(\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(\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) \]
      8. unpow3100.0%

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

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

        \[\leadsto {\left({\left(a \cdot a + b \cdot b\right)}^{\color{blue}{0.5}}\right)}^{\left(3 + 1\right)} + \left(4 \cdot \left(b \cdot b\right) - 1\right) \]
      11. unpow1/2100.0%

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

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

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

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

        \[\leadsto {\left(\mathsf{hypot}\left(a, b\right)\right)}^{4} + \left(\color{blue}{b \cdot \left(4 \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 99.1%

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

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

    if 5e3 < (*.f64 b b)

    1. Initial program 99.9%

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

        \[\leadsto \left(\color{blue}{{\left(a \cdot a + b \cdot b\right)}^{1}} \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) \]
      7. sqr-pow99.9%

        \[\leadsto \left(\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(\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) \]
      8. unpow399.9%

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

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

        \[\leadsto {\left({\left(a \cdot a + b \cdot b\right)}^{\color{blue}{0.5}}\right)}^{\left(3 + 1\right)} + \left(4 \cdot \left(b \cdot b\right) - 1\right) \]
      11. unpow1/2100.0%

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

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

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

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

        \[\leadsto {\left(\mathsf{hypot}\left(a, b\right)\right)}^{4} + \left(\color{blue}{b \cdot \left(4 \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. Step-by-step derivation
      1. hypot-udef100.0%

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

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

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

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

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

        \[\leadsto \color{blue}{\left(\left(a \cdot a + b \cdot b\right) \cdot \left(b \cdot b\right) + \left(a \cdot a + b \cdot b\right) \cdot \left(a \cdot a\right)\right)} + \mathsf{fma}\left(b, b \cdot 4, -1\right) \]
      7. add-sqr-sqrt87.0%

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

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

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

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

        \[\leadsto \left({\left(\mathsf{hypot}\left(a, b\right)\right)}^{2} \cdot \color{blue}{{b}^{2}} + \left(a \cdot a + b \cdot b\right) \cdot \left(a \cdot a\right)\right) + \mathsf{fma}\left(b, b \cdot 4, -1\right) \]
      12. pow-prod-down87.0%

        \[\leadsto \left(\color{blue}{{\left(\mathsf{hypot}\left(a, b\right) \cdot b\right)}^{2}} + \left(a \cdot a + b \cdot b\right) \cdot \left(a \cdot a\right)\right) + \mathsf{fma}\left(b, b \cdot 4, -1\right) \]
      13. add-sqr-sqrt87.0%

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

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

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

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

        \[\leadsto \left({\left(\mathsf{hypot}\left(a, b\right) \cdot b\right)}^{2} + {\left(\mathsf{hypot}\left(a, b\right)\right)}^{2} \cdot \color{blue}{{a}^{2}}\right) + \mathsf{fma}\left(b, b \cdot 4, -1\right) \]
      18. pow-prod-down99.9%

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

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

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

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

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

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

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

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

Alternative 6: 68.9% accurate, 1.1× speedup?

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

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

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


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

    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) \]
      6. unpow199.9%

        \[\leadsto \left(\color{blue}{{\left(a \cdot a + b \cdot b\right)}^{1}} \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) \]
      7. sqr-pow99.9%

        \[\leadsto \left(\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(\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) \]
      8. unpow3100.0%

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

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

        \[\leadsto {\left({\left(a \cdot a + b \cdot b\right)}^{\color{blue}{0.5}}\right)}^{\left(3 + 1\right)} + \left(4 \cdot \left(b \cdot b\right) - 1\right) \]
      11. unpow1/2100.0%

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

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

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

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

        \[\leadsto {\left(\mathsf{hypot}\left(a, b\right)\right)}^{4} + \left(\color{blue}{b \cdot \left(4 \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 0 52.7%

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

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

    if 1.00000000000000008e-5 < (*.f64 b b)

    1. Initial program 99.9%

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

        \[\leadsto \left(\color{blue}{{\left(a \cdot a + b \cdot b\right)}^{1}} \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) \]
      7. sqr-pow99.9%

        \[\leadsto \left(\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(\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) \]
      8. unpow399.9%

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

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

        \[\leadsto {\left({\left(a \cdot a + b \cdot b\right)}^{\color{blue}{0.5}}\right)}^{\left(3 + 1\right)} + \left(4 \cdot \left(b \cdot b\right) - 1\right) \]
      11. unpow1/2100.0%

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

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

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

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

        \[\leadsto {\left(\mathsf{hypot}\left(a, b\right)\right)}^{4} + \left(\color{blue}{b \cdot \left(4 \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. Step-by-step derivation
      1. hypot-udef100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left({\left(\mathsf{hypot}\left(a, b\right) \cdot b\right)}^{2} + {\left(\mathsf{hypot}\left(a, b\right)\right)}^{2} \cdot \color{blue}{{a}^{2}}\right) + \mathsf{fma}\left(b, b \cdot 4, -1\right) \]
      18. pow-prod-down99.9%

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

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

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

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

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

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

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

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

Alternative 7: 59.5% accurate, 6.8× speedup?

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

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

\mathbf{elif}\;b \cdot b \leq 10^{+301}:\\
\;\;\;\;2 \cdot \left(\left(a \cdot a\right) \cdot \left(b \cdot b\right)\right)\\

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


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

    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) \]
      6. unpow199.9%

        \[\leadsto \left(\color{blue}{{\left(a \cdot a + b \cdot b\right)}^{1}} \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) \]
      7. sqr-pow99.9%

        \[\leadsto \left(\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(\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) \]
      8. unpow3100.0%

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

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

        \[\leadsto {\left({\left(a \cdot a + b \cdot b\right)}^{\color{blue}{0.5}}\right)}^{\left(3 + 1\right)} + \left(4 \cdot \left(b \cdot b\right) - 1\right) \]
      11. unpow1/2100.0%

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

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

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

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

        \[\leadsto {\left(\mathsf{hypot}\left(a, b\right)\right)}^{4} + \left(\color{blue}{b \cdot \left(4 \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 0 52.7%

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

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

    if 1.00000000000000008e-5 < (*.f64 b b) < 1.00000000000000005e301

    1. Initial program 99.7%

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

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

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

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

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

        \[\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) \]
      6. unpow199.8%

        \[\leadsto \left(\color{blue}{{\left(a \cdot a + b \cdot b\right)}^{1}} \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) \]
      7. sqr-pow99.8%

        \[\leadsto \left(\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(\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) \]
      8. unpow399.8%

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

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

        \[\leadsto {\left({\left(a \cdot a + b \cdot b\right)}^{\color{blue}{0.5}}\right)}^{\left(3 + 1\right)} + \left(4 \cdot \left(b \cdot b\right) - 1\right) \]
      11. unpow1/2100.0%

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

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

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

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

        \[\leadsto {\left(\mathsf{hypot}\left(a, b\right)\right)}^{4} + \left(\color{blue}{b \cdot \left(4 \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. Step-by-step derivation
      1. hypot-udef100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto 2 \cdot \left(\color{blue}{\left(a \cdot a\right)} \cdot {b}^{2}\right) \]
      2. *-commutative35.7%

        \[\leadsto 2 \cdot \color{blue}{\left({b}^{2} \cdot \left(a \cdot a\right)\right)} \]
      3. unpow235.7%

        \[\leadsto 2 \cdot \left(\color{blue}{\left(b \cdot b\right)} \cdot \left(a \cdot a\right)\right) \]
    11. Simplified35.7%

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

    if 1.00000000000000005e301 < (*.f64 b b)

    1. Initial program 100.0%

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

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

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

        \[\leadsto \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-pow100.0%

        \[\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) \]
      6. unpow1100.0%

        \[\leadsto \left(\color{blue}{{\left(a \cdot a + b \cdot b\right)}^{1}} \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) \]
      7. sqr-pow100.0%

        \[\leadsto \left(\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(\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) \]
      8. unpow3100.0%

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

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

        \[\leadsto {\left({\left(a \cdot a + b \cdot b\right)}^{\color{blue}{0.5}}\right)}^{\left(3 + 1\right)} + \left(4 \cdot \left(b \cdot b\right) - 1\right) \]
      11. unpow1/2100.0%

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

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

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

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

        \[\leadsto {\left(\mathsf{hypot}\left(a, b\right)\right)}^{4} + \left(\color{blue}{b \cdot \left(4 \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 98.8%

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

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

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

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

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

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

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

Alternative 8: 51.7% accurate, 12.8× speedup?

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

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

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


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

    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) \]
      6. unpow199.9%

        \[\leadsto \left(\color{blue}{{\left(a \cdot a + b \cdot b\right)}^{1}} \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) \]
      7. sqr-pow99.9%

        \[\leadsto \left(\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(\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) \]
      8. unpow3100.0%

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

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

        \[\leadsto {\left({\left(a \cdot a + b \cdot b\right)}^{\color{blue}{0.5}}\right)}^{\left(3 + 1\right)} + \left(4 \cdot \left(b \cdot b\right) - 1\right) \]
      11. unpow1/2100.0%

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

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

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

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

        \[\leadsto {\left(\mathsf{hypot}\left(a, b\right)\right)}^{4} + \left(\color{blue}{b \cdot \left(4 \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 0 52.7%

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

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

    if 1.00000000000000008e-5 < (*.f64 b b)

    1. Initial program 99.9%

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

        \[\leadsto \left(\color{blue}{{\left(a \cdot a + b \cdot b\right)}^{1}} \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) \]
      7. sqr-pow99.9%

        \[\leadsto \left(\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(\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) \]
      8. unpow399.9%

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

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

        \[\leadsto {\left({\left(a \cdot a + b \cdot b\right)}^{\color{blue}{0.5}}\right)}^{\left(3 + 1\right)} + \left(4 \cdot \left(b \cdot b\right) - 1\right) \]
      11. unpow1/2100.0%

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

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

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

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

        \[\leadsto {\left(\mathsf{hypot}\left(a, b\right)\right)}^{4} + \left(\color{blue}{b \cdot \left(4 \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 73.3%

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

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

        \[\leadsto \color{blue}{{b}^{2} \cdot 4} \]
      2. unpow258.4%

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

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

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

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

Alternative 9: 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 \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) \]
    6. unpow199.9%

      \[\leadsto \left(\color{blue}{{\left(a \cdot a + b \cdot b\right)}^{1}} \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) \]
    7. sqr-pow99.9%

      \[\leadsto \left(\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(\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) \]
    8. unpow3100.0%

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

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

      \[\leadsto {\left({\left(a \cdot a + b \cdot b\right)}^{\color{blue}{0.5}}\right)}^{\left(3 + 1\right)} + \left(4 \cdot \left(b \cdot b\right) - 1\right) \]
    11. unpow1/2100.0%

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

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

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

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

      \[\leadsto {\left(\mathsf{hypot}\left(a, b\right)\right)}^{4} + \left(\color{blue}{b \cdot \left(4 \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 0 72.2%

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

    \[\leadsto \color{blue}{-1} \]
  6. Final simplification26.7%

    \[\leadsto -1 \]

Reproduce

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