Query:
```sql
SELECT round(avg(log(2) * number), 6) AS k FROM numbers(10000000)
GROUP BY (number % 2) * (number % 3), number % 3, number % 2
HAVING avg(log(2) * number) > 3465735.3 ORDER BY k
SETTINGS allow_experimental_analyzer=1, optimize_group_by_function_keys=0;
```
Output:
```
Ok.

0 rows in set. Elapsed: 0.079 sec. Processed 10.01 million rows, 80.06 MB (127.02 million rows/s., 1.02 GB/s.)
```

Query:
```sql
SELECT round(avg(log(2) * number), 6) AS k FROM numbers(10000000)
GROUP BY (number % 2) * (number % 3), number % 3, number % 2
HAVING avg(log(2) * number) > 3465735.3 ORDER BY k
SETTINGS allow_experimental_analyzer=0, optimize_group_by_function_keys=0;
```

Output:
```
┌──────────────k─┐
│   3465735.9028 │
│   3465735.9028 │
│ 3465736.595947 │
└────────────────┘

3 rows in set. Elapsed: 0.085 sec. Processed 10.01 million rows, 80.06 MB (117.56 million rows/s., 940.52 MB/s.)
```

cc @kitaisreal 
{
    switch (value.getType())
    {
        case Field::Types::UInt64: return static_cast<UInt64>(0);
        case Field::Types::Int64: return static_cast<Int64>(0);
        case Field::Types::Float64: return static_cast<Float64>(0);
        case Field::Types::UInt128: return static_cast<UInt128>(0);
        case Field::Types::Int128: return static_cast<Int128>(0);
        case Field::Types::UInt256: return static_cast<UInt256>(0);
        case Field::Types::Int256: return static_cast<Int256>(0);
        default:
            break;
    }
    throw Exception(ErrorCodes::BAD_TYPE_OF_FIELD, "Unexpected literal type in function");
}
/** Rewrites:   sum([multiply|divide]) -> [multiply|divide](sum)
  *             [min|max|avg]([multiply|divide|plus|minus]) -> [multiply|divide|plus|minus]([min|max|avg])
  *
  * TODO: Support `groupBitAnd`, `groupBitOr`, `groupBitXor` functions.
  * TODO: Support rewrite `f((2 * n) * n)` into '2 * f(n * n)'.
  */
class AggregateFunctionsArithmericOperationsVisitor : public InDepthQueryTreeVisitor<AggregateFunctionsArithmericOperationsVisitor>