| Alternative 1 | |
|---|---|
| Error | 0.13% |
| Cost | 13952 |
\[{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)
\]
(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)
Results
Initial program 0.27
Simplified0.02
[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)
\] |
Applied egg-rr0.28
Simplified0.28
[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)
\] |
Taylor expanded in a around 0 0.28
Simplified0.28
[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)
\] |
Taylor expanded in b around 0 0.01
Simplified0.01
[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)
\] |
Final simplification0.01
| Alternative 1 | |
|---|---|
| Error | 0.13% |
| Cost | 13952 |
| Alternative 2 | |
|---|---|
| Error | 0.27% |
| Cost | 7424 |
| Alternative 3 | |
|---|---|
| Error | 2.25% |
| Cost | 7300 |
| Alternative 4 | |
|---|---|
| Error | 2.37% |
| Cost | 6916 |
| Alternative 5 | |
|---|---|
| Error | 2.76% |
| Cost | 6788 |
| Alternative 6 | |
|---|---|
| Error | 18.5% |
| Cost | 704 |
| Alternative 7 | |
|---|---|
| Error | 35.04% |
| Cost | 448 |
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))