| Alternative 1 | |
|---|---|
| Error | 3.6 |
| Cost | 576 |
\[2 \cdot \left(a + \left(b + \left(c + d\right)\right)\right)
\]
(FPCore (a b c d) :precision binary64 (* (+ a (+ b (+ c d))) 2.0))
(FPCore (a b c d) :precision binary64 (* (+ (+ c b) (+ d a)) 2.0))
double code(double a, double b, double c, double d) {
return (a + (b + (c + d))) * 2.0;
}
double code(double a, double b, double c, double d) {
return ((c + b) + (d + a)) * 2.0;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = (a + (b + (c + d))) * 2.0d0
end function
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = ((c + b) + (d + a)) * 2.0d0
end function
public static double code(double a, double b, double c, double d) {
return (a + (b + (c + d))) * 2.0;
}
public static double code(double a, double b, double c, double d) {
return ((c + b) + (d + a)) * 2.0;
}
def code(a, b, c, d): return (a + (b + (c + d))) * 2.0
def code(a, b, c, d): return ((c + b) + (d + a)) * 2.0
function code(a, b, c, d) return Float64(Float64(a + Float64(b + Float64(c + d))) * 2.0) end
function code(a, b, c, d) return Float64(Float64(Float64(c + b) + Float64(d + a)) * 2.0) end
function tmp = code(a, b, c, d) tmp = (a + (b + (c + d))) * 2.0; end
function tmp = code(a, b, c, d) tmp = ((c + b) + (d + a)) * 2.0; end
code[a_, b_, c_, d_] := N[(N[(a + N[(b + N[(c + d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision]
code[a_, b_, c_, d_] := N[(N[(N[(c + b), $MachinePrecision] + N[(d + a), $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision]
\left(a + \left(b + \left(c + d\right)\right)\right) \cdot 2
\left(\left(c + b\right) + \left(d + a\right)\right) \cdot 2
Results
| Original | 3.6 |
|---|---|
| Target | 3.8 |
| Herbie | 0 |
Initial program 3.6
Applied egg-rr3.9
Simplified3.6
[Start]3.9 | \[ \left(\left({a}^{3} + {\left(b + \left(c + d\right)\right)}^{3}\right) \cdot \frac{1}{\mathsf{fma}\left(a, a, \left(b + \left(c + d\right)\right) \cdot \left(b + \left(\left(c + d\right) - a\right)\right)\right)}\right) \cdot 2
\] |
|---|---|
*-commutative [<=]3.9 | \[ \color{blue}{\left(\frac{1}{\mathsf{fma}\left(a, a, \left(b + \left(c + d\right)\right) \cdot \left(b + \left(\left(c + d\right) - a\right)\right)\right)} \cdot \left({a}^{3} + {\left(b + \left(c + d\right)\right)}^{3}\right)\right)} \cdot 2
\] |
associate-*l/ [=>]3.9 | \[ \color{blue}{\frac{1 \cdot \left({a}^{3} + {\left(b + \left(c + d\right)\right)}^{3}\right)}{\mathsf{fma}\left(a, a, \left(b + \left(c + d\right)\right) \cdot \left(b + \left(\left(c + d\right) - a\right)\right)\right)}} \cdot 2
\] |
*-lft-identity [=>]3.9 | \[ \frac{\color{blue}{{a}^{3} + {\left(b + \left(c + d\right)\right)}^{3}}}{\mathsf{fma}\left(a, a, \left(b + \left(c + d\right)\right) \cdot \left(b + \left(\left(c + d\right) - a\right)\right)\right)} \cdot 2
\] |
+-commutative [=>]3.9 | \[ \frac{{a}^{3} + {\color{blue}{\left(\left(c + d\right) + b\right)}}^{3}}{\mathsf{fma}\left(a, a, \left(b + \left(c + d\right)\right) \cdot \left(b + \left(\left(c + d\right) - a\right)\right)\right)} \cdot 2
\] |
associate-+r+ [<=]3.6 | \[ \frac{{a}^{3} + {\color{blue}{\left(c + \left(d + b\right)\right)}}^{3}}{\mathsf{fma}\left(a, a, \left(b + \left(c + d\right)\right) \cdot \left(b + \left(\left(c + d\right) - a\right)\right)\right)} \cdot 2
\] |
+-commutative [=>]3.6 | \[ \frac{{a}^{3} + {\left(c + \left(d + b\right)\right)}^{3}}{\mathsf{fma}\left(a, a, \color{blue}{\left(\left(c + d\right) + b\right)} \cdot \left(b + \left(\left(c + d\right) - a\right)\right)\right)} \cdot 2
\] |
associate-+r+ [<=]3.6 | \[ \frac{{a}^{3} + {\left(c + \left(d + b\right)\right)}^{3}}{\mathsf{fma}\left(a, a, \color{blue}{\left(c + \left(d + b\right)\right)} \cdot \left(b + \left(\left(c + d\right) - a\right)\right)\right)} \cdot 2
\] |
associate-+r- [=>]3.6 | \[ \frac{{a}^{3} + {\left(c + \left(d + b\right)\right)}^{3}}{\mathsf{fma}\left(a, a, \left(c + \left(d + b\right)\right) \cdot \color{blue}{\left(\left(b + \left(c + d\right)\right) - a\right)}\right)} \cdot 2
\] |
+-commutative [=>]3.6 | \[ \frac{{a}^{3} + {\left(c + \left(d + b\right)\right)}^{3}}{\mathsf{fma}\left(a, a, \left(c + \left(d + b\right)\right) \cdot \left(\color{blue}{\left(\left(c + d\right) + b\right)} - a\right)\right)} \cdot 2
\] |
associate--l+ [=>]3.6 | \[ \frac{{a}^{3} + {\left(c + \left(d + b\right)\right)}^{3}}{\mathsf{fma}\left(a, a, \left(c + \left(d + b\right)\right) \cdot \color{blue}{\left(\left(c + d\right) + \left(b - a\right)\right)}\right)} \cdot 2
\] |
Taylor expanded in a around 0 2.7
Simplified0
[Start]2.7 | \[ \left(c + \left(a + \left(d + b\right)\right)\right) \cdot 2
\] |
|---|---|
+-commutative [=>]2.7 | \[ \left(c + \color{blue}{\left(\left(d + b\right) + a\right)}\right) \cdot 2
\] |
+-commutative [=>]2.7 | \[ \left(c + \left(\color{blue}{\left(b + d\right)} + a\right)\right) \cdot 2
\] |
associate-+l+ [=>]0.0 | \[ \left(c + \color{blue}{\left(b + \left(d + a\right)\right)}\right) \cdot 2
\] |
+-commutative [<=]0.0 | \[ \left(c + \left(b + \color{blue}{\left(a + d\right)}\right)\right) \cdot 2
\] |
associate-+l+ [<=]0 | \[ \color{blue}{\left(\left(c + b\right) + \left(a + d\right)\right)} \cdot 2
\] |
+-commutative [=>]0 | \[ \left(\left(c + b\right) + \color{blue}{\left(d + a\right)}\right) \cdot 2
\] |
Final simplification0
| Alternative 1 | |
|---|---|
| Error | 3.6 |
| Cost | 576 |
| Alternative 2 | |
|---|---|
| Error | 2.7 |
| Cost | 576 |
| Alternative 3 | |
|---|---|
| Error | 55.2 |
| Cost | 320 |
| Alternative 4 | |
|---|---|
| Error | 60.0 |
| Cost | 192 |
| Alternative 5 | |
|---|---|
| Error | 56.6 |
| Cost | 192 |
herbie shell --seed 2023041
(FPCore (a b c d)
:name "Expression, p6"
:precision binary64
:pre (and (and (and (and (<= -14.0 a) (<= a -13.0)) (and (<= -3.0 b) (<= b -2.0))) (and (<= 3.0 c) (<= c 3.5))) (and (<= 12.5 d) (<= d 13.5)))
:herbie-target
(+ (* (+ a b) 2.0) (* (+ c d) 2.0))
(* (+ a (+ b (+ c d))) 2.0))