# Dot product abbreviation

**URL:** <https://discourse.julialang.org/t/dot-product-abbreviation/129719>\
**Category:** New to Julia\
**Tags:** question, parser\
**Created:** [June 7, 2025, 2:12am UTC](https://discourse.julialang.org/t/dot-product-abbreviation/129719 "2025-06-07T02:12:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![WalterMadelim](https://avatars.discourse-cdn.com/v4/letter/w/3e96dc/32.png) [@WalterMadelim](https://discourse.julialang.org/u/WalterMadelim)\
**Post date:** [June 7, 2025, 2:12am UTC](https://discourse.julialang.org/t/dot-product-abbreviation/129719/1 "2025-06-07T02:12:29Z")

</div>

I wonder why these can’t be parsed.

```julia
julia> a, b = 2, 3;

julia> a'b
6

julia> 2'b
6

julia> a'3
ERROR: ParseError:
# Error @ REPL[5]:1:3
a'3
# ╙ ── extra tokens after end of expression
Stacktrace:
 [1] top-level scope
   @ none:1

julia> 2'3
ERROR: ParseError:
# Error @ REPL[6]:1:3
2'3
# ╙ ── extra tokens after end of expression
Stacktrace:
 [1] top-level scope
   @ none:1

```

---

<div class="post-metadata">

**Author:** ![heliosdrm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heliosdrm/32/3851_2.png) [@heliosdrm](https://discourse.julialang.org/u/heliosdrm)\
**Post date:** [June 7, 2025, 5:46am UTC](https://discourse.julialang.org/t/dot-product-abbreviation/129719/2 "2025-06-07T05:46:40Z")

</div>

The apostrophe is not the dot product operator, but the adjoint operator (conjugate transpose). The dot product operator is the centred dot (`·`, which is in many keyboards, but can be also written by the escape secuence `\cdot` followed by tab). But you need the module `LinearAlgebra` to use it:

```julia
julia> using LinearAlgebra

julia> a, b = 2, 3;

julia> a·b
6

julia> 2·b
6

julia> a·3
6

julia> 2·3
6

```

Actually, I would also have expected an error in the two first examples (`a'b` and `2'b`). It seems that the “syntax sugar” that allows to omit the multiplication operator in expressions like `2b` (equivalent to `2*b`) made its magic also in them, but I thought that it only worked in the very specific case of numbers followed without space by a variable name .

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [June 7, 2025, 6:38am UTC](https://discourse.julialang.org/t/dot-product-abbreviation/129719/3 "2025-06-07T06:38:07Z")

</div>

I think the adjoint operator’s parsing is separate from numeric literal coefficients’, they just happen to both do implicit `*`.

```julia
julia> x = [3, 4im]
2-element Vector{Complex{Int64}}:
 3 + 0im
 0 + 4im

julia> x'x # compute the dot product, equivalently x' * x
25 + 0im

julia> Meta.@lower a'b
:($(Expr(:thunk, CodeInfo(
    @ none within `top-level scope`
1 ─ %1 = *
│ %2 = var"'"(a)
│ %3 = b
│ %4 = (%1)(%2, %3)
└── return %4
))))

```

---

<div class="post-metadata">

**Author:** ![WalterMadelim](https://avatars.discourse-cdn.com/v4/letter/w/3e96dc/32.png) [@WalterMadelim](https://discourse.julialang.org/u/WalterMadelim)\
**Post date:** [June 7, 2025, 9:18am UTC](https://discourse.julialang.org/t/dot-product-abbreviation/129719/4 "2025-06-07T09:18:39Z")

</div>

Also this

```julia
julia> 3'
3

julia> -3'
ERROR: ParseError:
# Error @ REPL[1]:1:3
-3'
# ╙ ── extra tokens after end of expression
Stacktrace:
 [1] top-level scope
   @ none:1

```

---

<div class="post-metadata">

**Author:** ![heliosdrm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heliosdrm/32/3851_2.png) [@heliosdrm](https://discourse.julialang.org/u/heliosdrm)\
**Post date:** [June 7, 2025, 3:43pm UTC](https://discourse.julialang.org/t/dot-product-abbreviation/129719/5 "2025-06-07T15:43:51Z")

</div>

Looks like a bug of the adjoint operator `'` when used next to number literals. True that at least the given examples are maybe too trivial, but the combination of cases where it works (without even a warning) at it doesn’t seem inconsistent.
