# About the show method for LinearAlgebra.jl objects

**URL:** <https://discourse.julialang.org/t/about-the-show-method-for-linearalgebra-jl-objects/128589>\
**Category:** New to Julia\
**Tags:** linearalgebra, show\
**Created:** [May 1, 2025, 4:20am UTC](https://discourse.julialang.org/t/about-the-show-method-for-linearalgebra-jl-objects/128589 "2025-05-01T04:20:34Z")\
**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:** [May 1, 2025, 4:20am UTC](https://discourse.julialang.org/t/about-the-show-method-for-linearalgebra-jl-objects/128589/1 "2025-05-01T04:20:34Z")

</div>

I find it convenient to type this command `@show A;` in Julia REPL, to get an executable code, e.g.,

```julia
julia> using LinearAlgebra

julia> A = rand(-9:9, 3, 3);

julia> @show A;
A = [0 -8 -2; -7 -2 3; 1 9 8]

```

Note that the last line can be readily copy-paste to a text editor and saved there.  
And after a while, we can recover the object `A` in REPL through the code saved in the text editor.

But we cannot enjoy the same experience for some other objects, e.g.

```julia
julia> S = Symmetric(A)
3×3 Symmetric{Int64, Matrix{Int64}}:
  0 -8 -2
 -8 -2 3
 -2 3 8

julia> @show S;
S = [0 -8 -2; -8 -2 3; -2 3 8]

```

Note that the style is plain, although `S` is Symmetric.

Another example,

```julia
julia> B = Bidiagonal(A, :U)
3×3 Bidiagonal{Int64, Vector{Int64}}:
 0 -8 ⋅
 ⋅ -2 3
 ⋅ ⋅ 8

julia> @show B;
B = 3×3 Bidiagonal{Int64, Vector{Int64}}:
 diag: 0 -2 8
 super: -8 3

```

This time, there is a proper “show”, but the generated lines are not executable.

Can we improve this somehow?

---

<div class="post-metadata">

**Author:** ![jishnub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jishnub/32/33620_2.png) [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Post date:** [May 1, 2025, 5:22am UTC](https://discourse.julialang.org/t/about-the-show-method-for-linearalgebra-jl-objects/128589/2 "2025-05-01T05:22:50Z")

</div>

Yes, the `Bidiagonal` show has been updated in v1.12 (I think). There is a slight issue with show for a `Symmetric`, but it’s also in the works.

---

<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:** [May 1, 2025, 5:26am UTC](https://discourse.julialang.org/t/about-the-show-method-for-linearalgebra-jl-objects/128589/3 "2025-05-01T05:26:25Z")

</div>

What is that slight issue?

And here is a Symmetric-related issue, please take a look: [Retaining the property of Symmetric? - #4 by WalterMadelim](https://discourse.julialang.org/t/retaining-the-property-of-symmetric/127437/4)

---

<div class="post-metadata">

**Author:** ![jishnub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jishnub/32/33620_2.png) [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Post date:** [May 1, 2025, 8:57am UTC](https://discourse.julialang.org/t/about-the-show-method-for-linearalgebra-jl-objects/128589/4 "2025-05-01T08:57:23Z")

</div>

You can have a look at this PR:

> <https://github.com/JuliaLang/julia/pull/56013>
>
> After this,
> \`\`\`julia
> julia\> A = rand(2,2);
> 
> julia\> H = Hermitian(A)
> 2×2 Her…mitian{Float64, Matrix{Float64}}:
> 0.889108 0.264298
> 0.264298 0.234985
> 
> julia\> println(H)
> Hermitian(\[0.8891078167175059 0.26429820656950753; 0.26429820656950753 0.23498548977257172\])
> 
> julia\> S = Symmetric(A)
> 2×2 Symmetric{Float64, Matrix{Float64}}:
> 0.889108 0.264298
> 0.264298 0.234985
> 
> julia\> println(S)
> Symmetric(\[0.8891078167175059 0.26429820656950753; 0.26429820656950753 0.23498548977257172\])
> 
> julia\> U = UpperTriangular(A)
> 2×2 UpperTriangular{Float64, Matrix{Float64}}:
> 0.889108 0.264298
> ⋅ 0.234985
> 
> julia\> println(U)
> UpperTriangular(\[0.8891078167175059 0.26429820656950753; 0.0 0.23498548977257172\])
> 
> julia\> U = UnitUpperTriangular(A)
> 2×2 UnitUpperTriangular{Float64, Matrix{Float64}}:
> 1.0 0.264298
> ⋅ 1.0
> 
> julia\> println(U)
> UnitUpperTriangular(\[1.0 0.26429820656950753; 0.0 1.0\])
> 
> julia\> L = LowerTriangular(A)
> 2×2 LowerTriangular{Float64, Matrix{Float64}}:
> 0.889108 ⋅ 
> 0.2504 0.234985
> 
> julia\> println(L)
> LowerTriangular(\[0.8891078167175059 0.0; 0.2503997651590879 0.23498548977257172\])
> 
> julia\> L = UnitLowerTriangular(A)
> 2×2 UnitLowerTriangular{Float64, Matrix{Float64}}:
> 1.0 ⋅ 
> 0.2504 1.0
> 
> julia\> println(L)
> UnitLowerTriangular(\[1.0 0.0; 0.2503997651590879 1.0\])
> \`\`\`
> The displayed form is now a valid constructor, and may be copy-pasted to reconstruct the object.

There were issues with how block arrays were being printed, but it’s worth reviving this again.

---

<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:** [May 1, 2025, 9:32am UTC](https://discourse.julialang.org/t/about-the-show-method-for-linearalgebra-jl-objects/128589/5 "2025-05-01T09:32:04Z")

</div>

What do you mean by “block array”? is this one?

```julia
julia> S = [rand(-9:9, 2, 2) for i in 1:2, j in 1:2]
2×2 Matrix{Matrix{Int64}}:
 [4 4; 3 7] [6 -4; 8 -1]
 [3 7; -4 -9] [5 -7; -2 9]

julia> S = Symmetric(S)
2×2 Symmetric{AbstractMatrix, Matrix{Matrix{Int64}}}:
 [4 4; 4 7] [6 -4; 8 -1]
 [6 8; -4 -1] [5 -7; -7 9]

julia> @show S;
S = AbstractMatrix[[4 4; 4 7] [6 -4; 8 -1]; [6 8; -4 -1] [5 -7; -7 9]]

```

(This is my first time to come up with code like this. Who would write this? I think)

I guess it suffices to have the normal case work properly.
