| 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) (+ 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 ((b + c) + (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 = ((b + c) + (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 ((b + c) + (d + a)) * 2.0;
}
def code(a, b, c, d): return (a + (b + (c + d))) * 2.0
def code(a, b, c, d): return ((b + c) + (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(b + c) + 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 = ((b + c) + (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[(b + c), $MachinePrecision] + N[(d + a), $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision]
\left(a + \left(b + \left(c + d\right)\right)\right) \cdot 2
\left(\left(b + c\right) + \left(d + a\right)\right) \cdot 2
Results
| Original | 94.3% |
|---|---|
| Target | 94.0% |
| Herbie | 100.0% |
Initial program 94.3%
Applied egg-rr93.9%
[Start]94.3 | \[ \left(a + \left(b + \left(c + d\right)\right)\right) \cdot 2
\] |
|---|---|
flip-+ [=>]93.9 | \[ \color{blue}{\frac{a \cdot a - \left(b + \left(c + d\right)\right) \cdot \left(b + \left(c + d\right)\right)}{a - \left(b + \left(c + d\right)\right)}} \cdot 2
\] |
div-inv [=>]93.9 | \[ \color{blue}{\left(\left(a \cdot a - \left(b + \left(c + d\right)\right) \cdot \left(b + \left(c + d\right)\right)\right) \cdot \frac{1}{a - \left(b + \left(c + d\right)\right)}\right)} \cdot 2
\] |
*-commutative [=>]93.9 | \[ \color{blue}{\left(\frac{1}{a - \left(b + \left(c + d\right)\right)} \cdot \left(a \cdot a - \left(b + \left(c + d\right)\right) \cdot \left(b + \left(c + d\right)\right)\right)\right)} \cdot 2
\] |
pow2 [=>]93.9 | \[ \left(\frac{1}{a - \left(b + \left(c + d\right)\right)} \cdot \left(a \cdot a - \color{blue}{{\left(b + \left(c + d\right)\right)}^{2}}\right)\right) \cdot 2
\] |
Applied egg-rr100.0%
[Start]93.9 | \[ \left(\frac{1}{a - \left(b + \left(c + d\right)\right)} \cdot \left(a \cdot a - {\left(b + \left(c + d\right)\right)}^{2}\right)\right) \cdot 2
\] |
|---|---|
associate-*l/ [=>]93.9 | \[ \color{blue}{\frac{1 \cdot \left(a \cdot a - {\left(b + \left(c + d\right)\right)}^{2}\right)}{a - \left(b + \left(c + d\right)\right)}} \cdot 2
\] |
*-un-lft-identity [<=]93.9 | \[ \frac{\color{blue}{a \cdot a - {\left(b + \left(c + d\right)\right)}^{2}}}{a - \left(b + \left(c + d\right)\right)} \cdot 2
\] |
unpow2 [=>]93.9 | \[ \frac{a \cdot a - \color{blue}{\left(b + \left(c + d\right)\right) \cdot \left(b + \left(c + d\right)\right)}}{a - \left(b + \left(c + d\right)\right)} \cdot 2
\] |
flip-+ [<=]94.3 | \[ \color{blue}{\left(a + \left(b + \left(c + d\right)\right)\right)} \cdot 2
\] |
+-commutative [=>]94.3 | \[ \color{blue}{\left(\left(b + \left(c + d\right)\right) + a\right)} \cdot 2
\] |
associate-+r+ [=>]95.7 | \[ \left(\color{blue}{\left(\left(b + c\right) + d\right)} + a\right) \cdot 2
\] |
associate-+l+ [=>]100.0 | \[ \color{blue}{\left(\left(b + c\right) + \left(d + a\right)\right)} \cdot 2
\] |
Final simplification100.0%
| Alternative 1 | |
|---|---|
| Accuracy | 94.3% |
| Cost | 576 |
| Alternative 2 | |
|---|---|
| Accuracy | 95.7% |
| Cost | 576 |
| Alternative 3 | |
|---|---|
| Accuracy | 14.3% |
| Cost | 452 |
| Alternative 4 | |
|---|---|
| Accuracy | 12.4% |
| Cost | 324 |
| Alternative 5 | |
|---|---|
| Accuracy | 6.3% |
| Cost | 192 |
herbie shell --seed 2023140
(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))