Average Error: 0.2 → 0.0
Time: 8.5s
Precision: binary64
Cost: 19776
\[\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
\[{\left(\mathsf{hypot}\left(a, b\right)\right)}^{4} + \mathsf{fma}\left(b \cdot b, 4, -1\right) \]
(FPCore (a b)
 :precision binary64
 (- (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (* b b))) 1.0))
(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(((a * a) + (b * b)), 2.0) + (4.0 * (b * b))) - 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(Float64((Float64(Float64(a * a) + Float64(b * b)) ^ 2.0) + Float64(4.0 * Float64(b * b))) - 1.0)
end
function code(a, b)
	return Float64((hypot(a, b) ^ 4.0) + fma(Float64(b * b), 4.0, -1.0))
end
code[a_, b_] := N[(N[(N[Power[N[(N[(a * a), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[(4.0 * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]
code[a_, b_] := N[(N[Power[N[Sqrt[a ^ 2 + b ^ 2], $MachinePrecision], 4.0], $MachinePrecision] + N[(N[(b * b), $MachinePrecision] * 4.0 + -1.0), $MachinePrecision]), $MachinePrecision]
\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right) - 1
{\left(\mathsf{hypot}\left(a, b\right)\right)}^{4} + \mathsf{fma}\left(b \cdot b, 4, -1\right)

Error

Derivation

  1. Initial program 0.2

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

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

    [Start]0.2

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

    associate--l+ [=>]0.2

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

    unpow2 [=>]0.2

    \[ \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) \]

    unpow1 [<=]0.2

    \[ \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) \]

    sqr-pow [=>]0.2

    \[ \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) \]

    associate-*r* [=>]0.1

    \[ \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) \]

    *-commutative [<=]0.1

    \[ \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)\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) \]

    unpow1 [<=]0.1

    \[ \left({\left(a \cdot a + b \cdot b\right)}^{\left(\frac{1}{2}\right)} \cdot \color{blue}{{\left(a \cdot a + b \cdot b\right)}^{1}}\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) \]

    sqr-pow [=>]0.1

    \[ \left({\left(a \cdot a + b \cdot b\right)}^{\left(\frac{1}{2}\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)}\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) \]

    cube-unmult [=>]0.1

    \[ \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) \]

    pow-plus [=>]0.0

    \[ \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) \]

    metadata-eval [=>]0.0

    \[ {\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) \]

    unpow1/2 [=>]0.0

    \[ {\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) \]

    hypot-def [=>]0.0

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

    metadata-eval [=>]0.0

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

    *-commutative [=>]0.0

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

    fma-neg [=>]0.0

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

    metadata-eval [=>]0.0

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

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

Alternatives

Alternative 1
Error0.2
Cost13696
\[-1 + \left({\left(\mathsf{fma}\left(b, b, a \cdot a\right)\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right) \]
Alternative 2
Error1.9
Cost7688
\[\begin{array}{l} t_0 := \left(b \cdot b\right) \cdot \left(4 + \left(a \cdot a\right) \cdot 2\right)\\ \mathbf{if}\;b \leq -3.4:\\ \;\;\;\;{b}^{4} + t_0\\ \mathbf{elif}\;b \leq 1.8 \cdot 10^{-13}:\\ \;\;\;\;-1 + \left(t_0 + {a}^{4}\right)\\ \mathbf{else}:\\ \;\;\;\;-1 + \left(4 \cdot \left(b \cdot b\right) + {b}^{4}\right)\\ \end{array} \]
Alternative 3
Error0.2
Cost7424
\[-1 + \left(4 \cdot \left(b \cdot b\right) + {\left(b \cdot b + a \cdot a\right)}^{2}\right) \]
Alternative 4
Error2.0
Cost7300
\[\begin{array}{l} \mathbf{if}\;b \cdot b \leq 10^{-27}:\\ \;\;\;\;-1 + {a}^{4}\\ \mathbf{else}:\\ \;\;\;\;-1 + \left(4 \cdot \left(b \cdot b\right) + {b}^{4}\right)\\ \end{array} \]
Alternative 5
Error2.0
Cost7236
\[\begin{array}{l} \mathbf{if}\;b \cdot b \leq 10^{-27}:\\ \;\;\;\;-1 + {a}^{4}\\ \mathbf{else}:\\ \;\;\;\;-1 + b \cdot \left(b \cdot \mathsf{fma}\left(b, b, 4\right)\right)\\ \end{array} \]
Alternative 6
Error2.0
Cost6916
\[\begin{array}{l} \mathbf{if}\;b \cdot b \leq 10^{-27}:\\ \;\;\;\;-1 + {a}^{4}\\ \mathbf{else}:\\ \;\;\;\;-1 + \left(b \cdot b\right) \cdot \left(4 + b \cdot b\right)\\ \end{array} \]
Alternative 7
Error2.1
Cost1220
\[\begin{array}{l} \mathbf{if}\;b \cdot b \leq 10^{-27}:\\ \;\;\;\;-1 + \left(4 \cdot \left(b \cdot b\right) + \left(a \cdot a\right) \cdot \left(a \cdot a\right)\right)\\ \mathbf{else}:\\ \;\;\;\;-1 + \left(b \cdot b\right) \cdot \left(4 + b \cdot b\right)\\ \end{array} \]
Alternative 8
Error11.8
Cost704
\[-1 + \left(b \cdot b\right) \cdot \left(4 + b \cdot b\right) \]
Alternative 9
Error12.8
Cost576
\[-1 + \left(b \cdot b\right) \cdot \left(b \cdot b\right) \]
Alternative 10
Error22.5
Cost448
\[-1 + 4 \cdot \left(b \cdot b\right) \]
Alternative 11
Error23.5
Cost64
\[-1 \]

Error

Reproduce

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