# Strange behavior for subtraction AST?

**URL:** https://discourse.julialang.org/t/strange-behavior-for-subtraction-ast/10258
**Category:** General Usage
**Tags:** question
**Created:** [April 10, 2018, 7:30am UTC](https://discourse.julialang.org/t/strange-behavior-for-subtraction-ast/10258 "2018-04-10T07:30:23Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![chakravala](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chakravala/32/6832_2.png) [@chakravala](https://discourse.julialang.org/u/chakravala)
#### Post date: [April 10, 2018, 7:30am UTC](https://discourse.julialang.org/t/strange-behavior-for-subtraction-ast/10258/1 "2018-04-10T07:30:23Z")

</div>

Hi, I was wondering why the Julia AST automatically splits subtraction into multiple operations:

```nohighlight
julia> :(x-y-z)
:((x - y) - z)

julia> dump(ans)
Expr
  head: Symbol call
  args: Array{Any}((3,))
    1: Symbol -
    2: Expr
      head: Symbol call
      args: Array{Any}((3,))
        1: Symbol -
        2: Symbol x
        3: Symbol y
      typ: Any
    3: Symbol z
  typ: Any

```

versus

```nohighlight
julia> :(-(x,y,z))
:(-(x, y, z))

julia> dump(ans)
Expr
  head: Symbol call
  args: Array{Any}((4,))
    1: Symbol -
    2: Symbol x
    3: Symbol y
    4: Symbol z
  typ: Any

```

I would have thought that the second AST is simpler and more efficient code, but maybe it really doesn’t matter because the compiler optimizes it already. But I was wondering why the default behavior is to introduce an extra operation into the AST, could someone explain the reason behind that?

```nohighlight
julia> :(x+y+z) |> dump
Expr
  head: Symbol call
  args: Array{Any}((4,))
    1: Symbol +
    2: Symbol x
    3: Symbol y
    4: Symbol z
  typ: Any

```

for `+()` no extra operations get added into the AST automatically, but it does happen for `-()`.

I have come up with an algorithm that rewrites the AST in the simpler form, but I don’t know if it is a good idea to rewrite it, since the default behavior of splitting the operation might be there for a reason.

---

<div class="post-metadata">

### Author: ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)
#### Post date: [April 10, 2018, 1:31pm UTC](https://discourse.julialang.org/t/strange-behavior-for-subtraction-ast/10258/2 "2018-04-10T13:31:35Z")

</div>

This is how parsing operators normally works. The real question is why `+` doesn’t. The answer is that `*` and `+` (and IIRC `++`) are handled specially while all other operators are parsed in the standard binary left or right associative fashion.
