7676julia> @ket k₁; @ket k₂;
7777
7878julia> k₁ + k₂
79- ( |k₁⟩+|k₂⟩)
79+ |k₁⟩+|k₂⟩
8080```
8181"""
8282@withmetadata struct SAdd{T<: QObj } <: Symbolic{T}
@@ -107,17 +107,18 @@ basis(x::SAdd) = basis(first(x.dict).first)
107107const SAddBra = SAdd{AbstractBra}
108108function Base. show (io:: IO , x:: SAddBra )
109109 ordered_terms = sort ([repr (i) for i in arguments (x)])
110- print (io, " ( " * join (ordered_terms," +" ):: String * " ) " ) # type assert to help inference
110+ print (io, join (ordered_terms," +" ):: String ) # type assert to help inference
111111end
112112const SAddKet = SAdd{AbstractKet}
113113function Base. show (io:: IO , x:: SAddKet )
114114 ordered_terms = sort ([repr (i) for i in arguments (x)])
115- print (io, " ( " * join (ordered_terms," +" ):: String * " ) " ) # type assert to help inference
115+ print (io, join (ordered_terms," +" ):: String ) # type assert to help inference
116116end
117117const SAddOperator = SAdd{AbstractOperator}
118118function Base. show (io:: IO , x:: SAddOperator )
119- ordered_terms = sort ([repr (i) for i in arguments (x)])
120- print (io, " (" * join (ordered_terms," +" ):: String * " )" ) # type assert to help inference
119+ repr_func = x -> x isa STensor ? " (" * repr (x)* " )" : repr (x)
120+ ordered_terms = sort ([repr_func (i) for i in arguments (x)])
121+ print (io, join (ordered_terms," +" ):: String ) # type assert to help inference
121122end
122123
123124""" Symbolic application of operator on operator.
@@ -153,7 +154,10 @@ function Base.:(*)(x::Symbolic{AbstractOperator}, xs::Vararg{Symbolic{AbstractOp
153154 SZeroOperator ()
154155 end
155156end
156- Base. show (io:: IO , x:: SMulOperator ) = print (io, join (map (string, arguments (x))," " ))
157+ function Base. show (io:: IO , x:: SMulOperator )
158+ str_func = x -> x isa SAdd || x isa STensor ? " (" * string (x)* " )" : string (x)
159+ print (io, join (map (str_func, arguments (x))," " ))
160+ end
157161basis (x:: SMulOperator ) = basis (first (x. terms))
158162
159163""" Tensor product of quantum objects (kets, operators, or bras).
@@ -167,7 +171,7 @@ julia> k₁ ⊗ k₂
167171julia> @op A; @op B;
168172
169173julia> A ⊗ B
170- ( A⊗B)
174+ A⊗B
171175```
172176"""
173177@withmetadata struct STensor{T<: QObj } <: Symbolic{T}
@@ -196,6 +200,12 @@ Base.show(io::IO, x::STensorBra) = print(io, join(map(string, arguments(x)),""))
196200const STensorKet = STensor{AbstractKet}
197201Base. show (io:: IO , x:: STensorKet ) = print (io, join (map (string, arguments (x))," " ))
198202const STensorOperator = STensor{AbstractOperator}
199- Base. show (io:: IO , x:: STensorOperator ) = print (io, " (" * join (map (string, arguments (x))," ⊗" )* " )" )
203+ function Base. show (io:: IO , x:: STensorOperator )
204+ str_func = x -> x isa SAdd ? " (" * string (x)* " )" : string (x)
205+ print (io, join (map (str_func, arguments (x))," ⊗" ))
206+ end
200207const STensorSuperOperator = STensor{AbstractSuperOperator}
201- Base. show (io:: IO , x:: STensorSuperOperator ) = print (io, " (" * join (map (string, arguments (x))," ⊗" )* " )" )
208+ function Base. show (io:: IO , x:: STensorSuperOperator )
209+ str_func = x -> x isa SAdd ? " (" * string (x)* " )" : string (x)
210+ print (io, join (map (str_func, arguments (x))," ⊗" ))
211+ end
0 commit comments