# Where is backslash (\\) implemented?

**URL:** https://discourse.julialang.org/t/where-is-backslash-implemented/104693
**Category:** Numerics
**Tags:** question, package
**Created:** [October 7, 2023, 9:25am UTC](https://discourse.julialang.org/t/where-is-backslash-implemented/104693 "2023-10-07T09:25:42Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![SupernovaTitanium](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/supernovatitanium/32/202307_2.png) [@SupernovaTitanium](https://discourse.julialang.org/u/SupernovaTitanium)
#### Post date: [October 7, 2023, 9:25am UTC](https://discourse.julialang.org/t/where-is-backslash-implemented/104693/1 "2023-10-07T09:25:42Z")

</div>

Hi, I’m new to Julia. Recently, I’ve used the backslash (\) operator to solve a linear system. However, I don’t know how it is implemented. I wanted to know it so I traced the code.

I am able to locate to line 1110 at [julia/stdlib/LinearAlgebra/src/generic.jl at master · JuliaLang/julia (github.com)](https://github.com/JuliaLang/julia/blob/master/stdlib/LinearAlgebra/src/generic.jl)

However, I don’t know what code will do next. For example, what will be done in line 1126? I don’t see any definition of backslash operator (\) there.

---

<div class="post-metadata">

### Author: ![abraemer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abraemer/32/51403_2.png) [@abraemer](https://discourse.julialang.org/u/abraemer)
#### Post date: [October 7, 2023, 9:33am UTC](https://discourse.julialang.org/t/where-is-backslash-implemented/104693/2 "2023-10-07T09:33:55Z")

</div>

To find the specific code run in a function call you can simply use `julia> @edit myfun(arg1, arg2)` and then your favorite editor will pop up at the correct file and line.

Edit: I realized that I may have misunderstood your question. The short answer to “what happens when I do `A\B`?” is “it depends on what `A` and `B` are”. You can see that the function starting in line 1110 starts checking some different cases where better solutions exists or else uses the default fallback of `qr(A)\B` or `lu(A) \ B` for square matrices. So you’ll need to trace the calls further by for example `julia> @edit qr(A)\B`

---

<div class="post-metadata">

### Author: ![kellertuer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kellertuer/32/220707_2.png) [@kellertuer](https://discourse.julialang.org/u/kellertuer)
#### Post date: [October 7, 2023, 9:40am UTC](https://discourse.julialang.org/t/where-is-backslash-implemented/104693/3 "2023-10-07T09:40:10Z")

</div>

Welcome to the Julia Discourse!

In 1126 the qr decomposition is computed and for that (with multiple dispatch) this method

> <https://github.com/JuliaLang/julia/blob/60b10de5ec389f843e00ff719e60d3ad2d907e30/stdlib/LinearAlgebra/src/qr.jl#L734>

is called.

---

<div class="post-metadata">

### Author: ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)
#### Post date: [October 7, 2023, 9:41am UTC](https://discourse.julialang.org/t/where-is-backslash-implemented/104693/4 "2023-10-07T09:41:09Z")

</div>

Line 1116

```julia
return Diagonal(A) \ B

```

you find in  
Line 455 in [https://github.com/JuliaLang/julia/blob/master/stdlib/LinearAlgebra/src/diagonal.jl](https://github.com/JuliaLang/julia/blob/master/stdlib/LinearAlgebra/src/diagonal.jl)

```julia
julia> @which Diagonal([1 1;2 2])\[2 2 ; 2 2]
\(D::Diagonal, B::AbstractMatrix)
     @ LinearAlgebra C:\Users\Oli\.julia\juliaup\julia-1.9.3+0.x64.w64.mingw32\share\julia\stdlib\v1.9\LinearAlgebra\src\diagonal.jl:412

```

Local on my installed version its in line 412.

Just as an example. You find the other implementations/methods in a similar way.

---

<div class="post-metadata">

### Author: ![jd-foster](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jd-foster/32/35824_2.png) [@jd-foster](https://discourse.julialang.org/u/jd-foster)
#### Post date: [October 7, 2023, 9:44am UTC](https://discourse.julialang.org/t/where-is-backslash-implemented/104693/5 "2023-10-07T09:44:58Z")

</div>

In general, a subroutine in a LAPACK library outside julia may ultimately be called to solve the system: the default library that comes with julia is OpenBLAS.

---

<div class="post-metadata">

### Author: ![bertschi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bertschi/32/33462_2.png) [@bertschi](https://discourse.julialang.org/u/bertschi)
#### Post date: [October 7, 2023, 11:28am UTC](https://discourse.julialang.org/t/where-is-backslash-implemented/104693/6 "2023-10-07T11:28:21Z")

</div>

Shameless plug: You can try [TraceFuns.jl](https://github.com/bertschi/TraceFuns.jl) to see which methods are actually hit

```julia
@trace [1 2; 3 4] \ [1, 2] Base.:\
# Or for an even larger picture
import LinearAlgebra
@trace [1 2; 3 4] \ [1, 2] LinearAlgebra

```

---

<div class="post-metadata">

### Author: ![SupernovaTitanium](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/supernovatitanium/32/202307_2.png) [@SupernovaTitanium](https://discourse.julialang.org/u/SupernovaTitanium)
#### Post date: [October 8, 2023, 8:04am UTC](https://discourse.julialang.org/t/where-is-backslash-implemented/104693/7 "2023-10-08T08:04:19Z")

</div>

Thank you. I think I know how to trace the code now.

---

<div class="post-metadata">

### Author: ![SupernovaTitanium](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/supernovatitanium/32/202307_2.png) [@SupernovaTitanium](https://discourse.julialang.org/u/SupernovaTitanium)
#### Post date: [October 8, 2023, 8:05am UTC](https://discourse.julialang.org/t/where-is-backslash-implemented/104693/8 "2023-10-08T08:05:00Z")

</div>

Thank you. It is an interesting tool.

---

<div class="post-metadata">

### Author: ![SupernovaTitanium](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/supernovatitanium/32/202307_2.png) [@SupernovaTitanium](https://discourse.julialang.org/u/SupernovaTitanium)
#### Post date: [October 8, 2023, 8:06am UTC](https://discourse.julialang.org/t/where-is-backslash-implemented/104693/9 "2023-10-08T08:06:09Z")

</div>

Thank you. I know how to find the backslash for qr now.

---

<div class="post-metadata">

### Author: ![SupernovaTitanium](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/supernovatitanium/32/202307_2.png) [@SupernovaTitanium](https://discourse.julialang.org/u/SupernovaTitanium)
#### Post date: [October 8, 2023, 8:08am UTC](https://discourse.julialang.org/t/where-is-backslash-implemented/104693/10 "2023-10-08T08:08:15Z")

</div>

I try to use @edit qr(A)\b. However, it only opens the LinearAlgebra.jl. I still don’t know where I can find the implementation.
