?

Average Error: 0.27% → 0.01%
Time: 7.4s
Precision: binary64
Cost: 14016

?

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

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Initial program 0.27

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

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

    [Start]0.27

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

    associate--l+ [=>]0.28

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

    unpow2 [=>]0.28

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

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

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

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

    \[ \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) \]
  3. Applied egg-rr0.28

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

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

    [Start]0.28

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

    +-commutative [<=]0.28

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

    distribute-lft-out [=>]0.28

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

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

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

    [Start]0.28

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

    unpow2 [=>]0.28

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

    fma-def [=>]0.28

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

    unpow2 [=>]0.28

    \[ \mathsf{fma}\left(b, b, \color{blue}{a \cdot a}\right) \cdot \left(a \cdot a + b \cdot b\right) + \mathsf{fma}\left(b \cdot b, 4, -1\right) \]
  7. Taylor expanded in b around 0 0.01

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

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

    [Start]0.01

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

    associate-+r+ [=>]0.01

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

    +-commutative [=>]0.01

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

    associate-+r+ [<=]0.01

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

    associate--l+ [=>]0.01

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

    unpow2 [=>]0.01

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

    unpow2 [=>]0.01

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

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

Alternatives

Alternative 1
Error0.13%
Cost13952
\[{a}^{4} + \left(\left(b \cdot b\right) \cdot \left(b \cdot b + \mathsf{fma}\left(2, a \cdot a, 4\right)\right) + -1\right) \]
Alternative 2
Error0.27%
Cost7424
\[\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right) + -1 \]
Alternative 3
Error2.25%
Cost7300
\[\begin{array}{l} \mathbf{if}\;b \cdot b \leq 5 \cdot 10^{-14}:\\ \;\;\;\;{a}^{4} + -1\\ \mathbf{else}:\\ \;\;\;\;\left({b}^{4} + 4 \cdot \left(b \cdot b\right)\right) + -1\\ \end{array} \]
Alternative 4
Error2.37%
Cost6916
\[\begin{array}{l} \mathbf{if}\;b \cdot b \leq 5 \cdot 10^{-14}:\\ \;\;\;\;{a}^{4} + -1\\ \mathbf{else}:\\ \;\;\;\;\left(b \cdot b\right) \cdot \left(4 + b \cdot b\right) + -1\\ \end{array} \]
Alternative 5
Error2.76%
Cost6788
\[\begin{array}{l} \mathbf{if}\;a \cdot a \leq 0.5:\\ \;\;\;\;\left(b \cdot b\right) \cdot \left(4 + b \cdot b\right) + -1\\ \mathbf{else}:\\ \;\;\;\;{a}^{4}\\ \end{array} \]
Alternative 6
Error18.5%
Cost704
\[\left(b \cdot b\right) \cdot \left(4 + b \cdot b\right) + -1 \]
Alternative 7
Error35.04%
Cost448
\[b \cdot \left(4 \cdot b\right) + -1 \]

Error

Reproduce?

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