fix #22168, im*I+I should be shown as (1+1im)*I#22169
fix #22168, im*I+I should be shown as (1+1im)*I#22169KristofferC merged 4 commits intoJuliaLang:masterfrom
im*I+I should be shown as (1+1im)*I#22169Conversation
ararslan
left a comment
There was a problem hiding this comment.
Looks good to me. Thanks for the contribution!
base/linalg/uniformscaling.jl
Outdated
| ndims(J::UniformScaling) = 2 | ||
| getindex(J::UniformScaling, i::Integer,j::Integer) = ifelse(i==j,J.λ,zero(J.λ)) | ||
|
|
||
| show(io::IO, J::UniformScaling{T}) where {T<:Complex} = print(io, "$(typeof(J))\n($(J.λ))*I") |
There was a problem hiding this comment.
Could we do a check for the number of terms instead? Minor use case but this would still be wrong for quaternions.
There was a problem hiding this comment.
That's true. But if we do such a check we have to deal with strings. Don't know if it's OK to do so.
There was a problem hiding this comment.
Aren't we already dealing with strings? My idea was to add the parentheses if something like ismatch(r"[0-9]+ ?\+|\- ?[0-9]+", "$(J.λ)")
There was a problem hiding this comment.
Oh I see. How about just checking r"\w+\s*\+|\-\s*\w+" as there must be + or - between terms if there are more than one term.
There was a problem hiding this comment.
That was also my first version but I think negative reals become false positives here
julia> ismatch(r"\w+\s*\+|\-\s*\w+", "-1")
trueThere was a problem hiding this comment.
Ah I'm sorry. It's because of the misuse of | and we should use r"\w+\s*[\+\-]\s*\w+".
There was a problem hiding this comment.
Could you perhaps add tests for the things that wasn't completely right with the first regexp.
There was a problem hiding this comment.
I don't know what common things can be wrong with the first regexp, but I believe there could be situations when users define a type that doesn't contain digit-[plus/minus]-digit pattern, such as something like 1i+2j. (The current displays of complex and quaternion numbers have something like 0+0im so the first regexp always works with them.)
No description provided.