| Alternative 1 | |
|---|---|
| Accuracy | 94.3% |
| 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 (* (+ b (+ c (+ a d))) 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 (b + (c + (a + d))) * 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 = (b + (c + (a + d))) * 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 (b + (c + (a + d))) * 2.0;
}
def code(a, b, c, d): return (a + (b + (c + d))) * 2.0
def code(a, b, c, d): return (b + (c + (a + d))) * 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(b + Float64(c + Float64(a + d))) * 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 = (b + (c + (a + d))) * 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[(b + N[(c + N[(a + d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision]
\left(a + \left(b + \left(c + d\right)\right)\right) \cdot 2
\left(b + \left(c + \left(a + d\right)\right)\right) \cdot 2
Results
| Original | 94.3% |
|---|---|
| Target | 94.0% |
| Herbie | 100.0% |
Initial program 94.3%
Taylor expanded in a around 0 95.7%
Applied egg-rr97.2%
[Start]95.7 | \[ \left(c + \left(a + \left(d + b\right)\right)\right) \cdot 2
\] |
|---|---|
associate-+r+ [=>]100.0 | \[ \left(c + \color{blue}{\left(\left(a + d\right) + b\right)}\right) \cdot 2
\] |
flip3-+ [=>]97.2 | \[ \left(c + \color{blue}{\frac{{\left(a + d\right)}^{3} + {b}^{3}}{\left(a + d\right) \cdot \left(a + d\right) + \left(b \cdot b - \left(a + d\right) \cdot b\right)}}\right) \cdot 2
\] |
+-commutative [=>]97.2 | \[ \left(c + \frac{\color{blue}{{b}^{3} + {\left(a + d\right)}^{3}}}{\left(a + d\right) \cdot \left(a + d\right) + \left(b \cdot b - \left(a + d\right) \cdot b\right)}\right) \cdot 2
\] |
*-commutative [=>]97.2 | \[ \left(c + \frac{{b}^{3} + {\left(a + d\right)}^{3}}{\left(a + d\right) \cdot \left(a + d\right) + \left(b \cdot b - \color{blue}{b \cdot \left(a + d\right)}\right)}\right) \cdot 2
\] |
Simplified97.6%
[Start]97.2 | \[ \left(c + \frac{{b}^{3} + {\left(a + d\right)}^{3}}{\left(a + d\right) \cdot \left(a + d\right) + \left(b \cdot b - b \cdot \left(a + d\right)\right)}\right) \cdot 2
\] |
|---|---|
+-commutative [=>]97.2 | \[ \left(c + \frac{{b}^{3} + {\color{blue}{\left(d + a\right)}}^{3}}{\left(a + d\right) \cdot \left(a + d\right) + \left(b \cdot b - b \cdot \left(a + d\right)\right)}\right) \cdot 2
\] |
fma-def [=>]97.2 | \[ \left(c + \frac{{b}^{3} + {\left(d + a\right)}^{3}}{\color{blue}{\mathsf{fma}\left(a + d, a + d, b \cdot b - b \cdot \left(a + d\right)\right)}}\right) \cdot 2
\] |
+-commutative [=>]97.2 | \[ \left(c + \frac{{b}^{3} + {\left(d + a\right)}^{3}}{\mathsf{fma}\left(\color{blue}{d + a}, a + d, b \cdot b - b \cdot \left(a + d\right)\right)}\right) \cdot 2
\] |
+-commutative [=>]97.2 | \[ \left(c + \frac{{b}^{3} + {\left(d + a\right)}^{3}}{\mathsf{fma}\left(d + a, \color{blue}{d + a}, b \cdot b - b \cdot \left(a + d\right)\right)}\right) \cdot 2
\] |
distribute-lft-out-- [=>]97.6 | \[ \left(c + \frac{{b}^{3} + {\left(d + a\right)}^{3}}{\mathsf{fma}\left(d + a, d + a, \color{blue}{b \cdot \left(b - \left(a + d\right)\right)}\right)}\right) \cdot 2
\] |
+-commutative [=>]97.6 | \[ \left(c + \frac{{b}^{3} + {\left(d + a\right)}^{3}}{\mathsf{fma}\left(d + a, d + a, b \cdot \left(b - \color{blue}{\left(d + a\right)}\right)\right)}\right) \cdot 2
\] |
Taylor expanded in b around inf 100.0%
Simplified100.0%
[Start]100.0 | \[ \left(\left(c + b\right) - -1 \cdot \left(a + d\right)\right) \cdot 2
\] |
|---|---|
+-commutative [=>]100.0 | \[ \left(\color{blue}{\left(b + c\right)} - -1 \cdot \left(a + d\right)\right) \cdot 2
\] |
+-commutative [=>]100.0 | \[ \left(\left(b + c\right) - -1 \cdot \color{blue}{\left(d + a\right)}\right) \cdot 2
\] |
associate--l+ [=>]100.0 | \[ \color{blue}{\left(b + \left(c - -1 \cdot \left(d + a\right)\right)\right)} \cdot 2
\] |
mul-1-neg [=>]100.0 | \[ \left(b + \left(c - \color{blue}{\left(-\left(d + a\right)\right)}\right)\right) \cdot 2
\] |
+-commutative [<=]100.0 | \[ \left(b + \left(c - \left(-\color{blue}{\left(a + d\right)}\right)\right)\right) \cdot 2
\] |
Final simplification100.0%
| Alternative 1 | |
|---|---|
| Accuracy | 94.3% |
| Cost | 576 |
| Alternative 2 | |
|---|---|
| Accuracy | 95.1% |
| Cost | 576 |
| Alternative 3 | |
|---|---|
| Accuracy | 95.7% |
| Cost | 576 |
| Alternative 4 | |
|---|---|
| Accuracy | 13.8% |
| Cost | 320 |
| Alternative 5 | |
|---|---|
| Accuracy | 6.2% |
| Cost | 192 |
| Alternative 6 | |
|---|---|
| Accuracy | 11.6% |
| Cost | 192 |
herbie shell --seed 2023137
(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))