?

Average Error: 0.28% → 0.02%
Time: 8.8s
Precision: binary64
Cost: 14016

?

\[\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
\[\left({a}^{4} + \left(b \cdot b\right) \cdot \left(4 + 2 \cdot \left(a \cdot a\right)\right)\right) + \left({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 a 4.0) (* (* b b) (+ 4.0 (* 2.0 (* a a))))) (+ (pow 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(a, 4.0) + ((b * b) * (4.0 + (2.0 * (a * a))))) + (pow(b, 4.0) + -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 * b) * (4.0d0 + (2.0d0 * (a * a))))) + ((b ** 4.0d0) + (-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) + ((b * b) * (4.0 + (2.0 * (a * a))))) + (Math.pow(b, 4.0) + -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) + ((b * b) * (4.0 + (2.0 * (a * a))))) + (math.pow(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((a ^ 4.0) + Float64(Float64(b * b) * Float64(4.0 + Float64(2.0 * Float64(a * a))))) + Float64((b ^ 4.0) + -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 * b) * (4.0 + (2.0 * (a * a))))) + ((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[Power[a, 4.0], $MachinePrecision] + N[(N[(b * b), $MachinePrecision] * N[(4.0 + N[(2.0 * N[(a * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Power[b, 4.0], $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]
\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right) - 1
\left({a}^{4} + \left(b \cdot b\right) \cdot \left(4 + 2 \cdot \left(a \cdot a\right)\right)\right) + \left({b}^{4} + -1\right)

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Initial program 0.28

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

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

    [Start]0.28

    \[ \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. Taylor expanded in a around 0 0.01

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

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

    [Start]0.01

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

    sub-neg [=>]0.01

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

    metadata-eval [=>]0.01

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

    +-commutative [=>]0.01

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

    associate-+r+ [=>]0.01

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

    associate-+l+ [=>]0.01

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

    associate-*r* [=>]0.01

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

    distribute-rgt-in [<=]0.01

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

    *-commutative [<=]0.01

    \[ \left(\left({a}^{4} + {b}^{4}\right) + \color{blue}{\left(4 + 2 \cdot {a}^{2}\right) \cdot {b}^{2}}\right) + -1 \]
  5. Applied egg-rr0.02

    \[\leadsto \color{blue}{\left(\left({a}^{4} + \left(b \cdot b\right) \cdot \left(2 \cdot \left(a \cdot a\right)\right)\right) + \left(b \cdot b\right) \cdot 4\right)} + \left({b}^{4} + -1\right) \]
  6. Applied egg-rr0.02

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

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

Alternatives

Alternative 1
Error0.02%
Cost13504
\[-1 + \left({\left(\mathsf{hypot}\left(a, b\right)\right)}^{4} + b \cdot \left(4 \cdot b\right)\right) \]
Alternative 2
Error2.34%
Cost7688
\[\begin{array}{l} t_0 := \left(b \cdot b\right) \cdot \left(4 + 2 \cdot \left(a \cdot a\right)\right)\\ \mathbf{if}\;b \leq -0.00043:\\ \;\;\;\;-1 + \left({b}^{4} + 4 \cdot \left(b \cdot b\right)\right)\\ \mathbf{elif}\;b \leq 175:\\ \;\;\;\;\left({a}^{4} + t_0\right) + -1\\ \mathbf{else}:\\ \;\;\;\;{b}^{4} + t_0\\ \end{array} \]
Alternative 3
Error2.66%
Cost7560
\[\begin{array}{l} \mathbf{if}\;b \leq -2 \cdot 10^{-8}:\\ \;\;\;\;-1 + \left({b}^{4} + 4 \cdot \left(b \cdot b\right)\right)\\ \mathbf{elif}\;b \leq 175:\\ \;\;\;\;{a}^{4} + -1\\ \mathbf{else}:\\ \;\;\;\;{b}^{4} + \left(b \cdot b\right) \cdot \left(4 + 2 \cdot \left(a \cdot a\right)\right)\\ \end{array} \]
Alternative 4
Error0.28%
Cost7424
\[-1 + \left({\left(b \cdot b + a \cdot a\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right) \]
Alternative 5
Error2.72%
Cost7172
\[\begin{array}{l} t_0 := 4 \cdot \left(b \cdot b\right)\\ \mathbf{if}\;b \leq -1.75 \cdot 10^{-8}:\\ \;\;\;\;-1 + \left({b}^{4} + t_0\right)\\ \mathbf{elif}\;b \leq 175:\\ \;\;\;\;{a}^{4} + -1\\ \mathbf{else}:\\ \;\;\;\;t_0 + \left(b \cdot b\right) \cdot \left(b \cdot b + 2 \cdot \left(a \cdot a\right)\right)\\ \end{array} \]
Alternative 6
Error2.78%
Cost6920
\[\begin{array}{l} \mathbf{if}\;b \leq -2 \cdot 10^{-8}:\\ \;\;\;\;-1 + \left(b \cdot b\right) \cdot \left(4 + b \cdot b\right)\\ \mathbf{elif}\;b \leq 175:\\ \;\;\;\;{a}^{4} + -1\\ \mathbf{else}:\\ \;\;\;\;4 \cdot \left(b \cdot b\right) + \left(b \cdot b\right) \cdot \left(b \cdot b + 2 \cdot \left(a \cdot a\right)\right)\\ \end{array} \]
Alternative 7
Error18.54%
Cost960
\[-1 + \left(4 \cdot \left(b \cdot b\right) + \left(b \cdot b\right) \cdot \left(b \cdot b\right)\right) \]
Alternative 8
Error19.46%
Cost836
\[\begin{array}{l} \mathbf{if}\;b \cdot b \leq 2 \cdot 10^{-7}:\\ \;\;\;\;-1 + b \cdot \left(4 \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;\left(b \cdot b\right) \cdot \left(4 + b \cdot b\right)\\ \end{array} \]
Alternative 9
Error19.86%
Cost708
\[\begin{array}{l} \mathbf{if}\;b \cdot b \leq 2 \cdot 10^{-7}:\\ \;\;\;\;-1 + b \cdot \left(4 \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;\left(b \cdot b\right) \cdot \left(b \cdot b\right)\\ \end{array} \]
Alternative 10
Error18.54%
Cost704
\[-1 + \left(b \cdot b\right) \cdot \left(4 + b \cdot b\right) \]
Alternative 11
Error82.12%
Cost448
\[\left(b \cdot b\right) \cdot \left(b \cdot b\right) \]
Alternative 12
Error96.55%
Cost320
\[4 \cdot \left(b \cdot b\right) \]

Error

Reproduce?

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