# Elementwise operators

**URL:** <https://discourse.julialang.org/t/elementwise-operators/19529>\
**Category:** General Usage\
**Created:** [January 11, 2019, 5:47pm UTC](https://discourse.julialang.org/t/elementwise-operators/19529 "2019-01-11T17:47:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rcnlee](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rcnlee/32/4107_2.png) [@rcnlee](https://discourse.julialang.org/u/rcnlee)\
**Post date:** [January 11, 2019, 5:47pm UTC](https://discourse.julialang.org/t/elementwise-operators/19529/1 "2019-01-11T17:47:59Z")

</div>

What’s actually going on under the hood when using elementwise operators? e.g., `z=x.*y`.

When I look at the syntax tree, the head is `call` and `arg[1]` is `:(.*)`. However, I’m not sure where that symbol is actually defined. It’s not in `Main` or `Base`. Using `@which` gives an error.

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [January 11, 2019, 5:56pm UTC](https://discourse.julialang.org/t/elementwise-operators/19529/2 "2019-01-11T17:56:10Z")

</div>

The syntax tree is only the first half of the syntax story. The second half happens in lowering, and that’s where the magic occurs:

```julia
julia> Meta.@lower z=x.*y
:($(Expr(:thunk, CodeInfo(
 1 ─ %1 = (Base.getproperty)(Base.Broadcast, :materialize) │
 │ %2 = (Base.getproperty)(Base.Broadcast, :broadcasted) │
 │ %3 = (%2)(*, x, y) │
 │ %4 = (%1)(%3) │
 │ z = %4 │
 └── return %4 │
))))

```

This belies a good deal of complexity, but that’s the entrance to the rabbit hole.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [January 12, 2019, 1:10pm UTC](https://discourse.julialang.org/t/elementwise-operators/19529/3 "2019-01-12T13:10:14Z")

</div>

The docs are broadcasting. The documentation on how broadcasting works, or at least how you interact with it, is here:

[https://docs.julialang.org/en/v1/manual/interfaces/index.html#man-interfaces-broadcasting-1](https://docs.julialang.org/en/v1/manual/interfaces/index.html#man-interfaces-broadcasting-1)

---

<div class="post-metadata">

**Author:** ![rcnlee](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rcnlee/32/4107_2.png) [@rcnlee](https://discourse.julialang.org/u/rcnlee)\
**Post date:** [January 12, 2019, 7:23pm UTC](https://discourse.julialang.org/t/elementwise-operators/19529/4 "2019-01-12T19:23:22Z")

</div>

Thank you both!
