?

Average Error: 0.2 → 0.0
Time: 7.4s
Precision: binary64
Cost: 20544

?

\[\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
\[\left(\mathsf{fma}\left(2, \left(a \cdot a\right) \cdot \left(b \cdot b\right), {b}^{4} + {a}^{4}\right) + \left(b \cdot b\right) \cdot 4\right) + -1 \]
(FPCore (a b)
 :precision binary64
 (- (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (* b b))) 1.0))
(FPCore (a b)
 :precision binary64
 (+
  (+ (fma 2.0 (* (* a a) (* b b)) (+ (pow b 4.0) (pow a 4.0))) (* (* 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 (fma(2.0, ((a * a) * (b * b)), (pow(b, 4.0) + pow(a, 4.0))) + ((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(Float64(fma(2.0, Float64(Float64(a * a) * Float64(b * b)), Float64((b ^ 4.0) + (a ^ 4.0))) + Float64(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[(N[(2.0 * N[(N[(a * a), $MachinePrecision] * N[(b * b), $MachinePrecision]), $MachinePrecision] + N[(N[Power[b, 4.0], $MachinePrecision] + N[Power[a, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(b * b), $MachinePrecision] * 4.0), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]
\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right) - 1
\left(\mathsf{fma}\left(2, \left(a \cdot a\right) \cdot \left(b \cdot b\right), {b}^{4} + {a}^{4}\right) + \left(b \cdot b\right) \cdot 4\right) + -1

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. Taylor expanded in a around 0 0.0

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

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

    [Start]0.0

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

    +-commutative [=>]0.0

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

    fma-def [=>]0.0

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

    unpow2 [=>]0.0

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

    unpow2 [=>]0.0

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

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

Alternatives

Alternative 1
Error0.0
Cost19776
\[{\left(\mathsf{hypot}\left(a, b\right)\right)}^{4} + \mathsf{fma}\left(b \cdot b, 4, -1\right) \]
Alternative 2
Error0.2
Cost7424
\[-1 + \left(\left(b \cdot b\right) \cdot 4 + {\left(a \cdot a + b \cdot b\right)}^{2}\right) \]
Alternative 3
Error1.9
Cost7305
\[\begin{array}{l} \mathbf{if}\;b \leq -0.00166 \lor \neg \left(b \leq 8.5 \cdot 10^{-12}\right):\\ \;\;\;\;-1 + \left({b}^{4} + \left(b \cdot b\right) \cdot 4\right)\\ \mathbf{else}:\\ \;\;\;\;{a}^{4} + -1\\ \end{array} \]
Alternative 4
Error1.9
Cost7241
\[\begin{array}{l} \mathbf{if}\;b \leq -0.0016 \lor \neg \left(b \leq 8.5 \cdot 10^{-12}\right):\\ \;\;\;\;-1 + b \cdot \left(b \cdot \mathsf{fma}\left(b, b, 4\right)\right)\\ \mathbf{else}:\\ \;\;\;\;{a}^{4} + -1\\ \end{array} \]
Alternative 5
Error2.0
Cost6920
\[\begin{array}{l} \mathbf{if}\;b \leq -0.00186:\\ \;\;\;\;-1 + \left(\left(b \cdot b\right) \cdot 4 + \left(b \cdot b\right) \cdot \left(b \cdot b\right)\right)\\ \mathbf{elif}\;b \leq 8.5 \cdot 10^{-12}:\\ \;\;\;\;{a}^{4} + -1\\ \mathbf{else}:\\ \;\;\;\;-1 + \left(b \cdot b\right) \cdot \left(b \cdot b + 4\right)\\ \end{array} \]
Alternative 6
Error11.9
Cost960
\[-1 + \left(\left(b \cdot b\right) \cdot 4 + \left(b \cdot b\right) \cdot \left(b \cdot b\right)\right) \]
Alternative 7
Error12.3
Cost836
\[\begin{array}{l} \mathbf{if}\;b \cdot b \leq 0.5:\\ \;\;\;\;-1 + b \cdot \left(b \cdot 4\right)\\ \mathbf{else}:\\ \;\;\;\;\left(b \cdot b\right) \cdot \left(b \cdot b + 4\right)\\ \end{array} \]
Alternative 8
Error13.1
Cost708
\[\begin{array}{l} \mathbf{if}\;b \cdot b \leq 5 \cdot 10^{-10}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;\left(b \cdot b\right) \cdot \left(b \cdot b\right)\\ \end{array} \]
Alternative 9
Error12.6
Cost708
\[\begin{array}{l} \mathbf{if}\;b \cdot b \leq 5:\\ \;\;\;\;-1 + b \cdot \left(b \cdot 4\right)\\ \mathbf{else}:\\ \;\;\;\;\left(b \cdot b\right) \cdot \left(b \cdot b\right)\\ \end{array} \]
Alternative 10
Error11.9
Cost704
\[-1 + \left(b \cdot b\right) \cdot \left(b \cdot b + 4\right) \]
Alternative 11
Error12.9
Cost576
\[-1 + \left(b \cdot b\right) \cdot \left(b \cdot b\right) \]
Alternative 12
Error24.0
Cost64
\[-1 \]

Error

Reproduce?

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