From f804bf9548412ae277ff63decf9ca3271811a059 Mon Sep 17 00:00:00 2001 From: apkille Date: Tue, 18 Jun 2024 15:43:21 -0400 Subject: [PATCH] fix SDagger --- src/QSymbolicsBase/predefined.jl | 5 ++++- test/test_express_opt.jl | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/QSymbolicsBase/predefined.jl b/src/QSymbolicsBase/predefined.jl index ffd934e..fa053ec 100644 --- a/src/QSymbolicsBase/predefined.jl +++ b/src/QSymbolicsBase/predefined.jl @@ -260,6 +260,9 @@ arguments(x::SDagger) = [x.obj] operation(x::SDagger) = dagger head(x::SDagger) = :dagger children(x::SDagger) = [:dagger, x.obj] +dagger(x::Symbolic{AbstractBra}) = SDagger{AbstractKet}(x) +dagger(x::Symbolic{AbstractKet}) = SDagger{AbstractBra}(x) +dagger(x::Symbolic{AbstractOperator}) = SDagger{AbstractOperator}(x) dagger(x::SKet) = SBra(x.name, x.basis) dagger(x::SScaledKet) = SScaledBra(conj(x.coeff), dagger(x.obj)) dagger(x::SAddKet) = SAddBra(Dict(dagger(k)=>v for (k,v) in pairs(x.dict))) @@ -282,7 +285,7 @@ dagger(x::SBraKet) = SBraKet(dagger(x.ket), dagger(x.bra)) dagger(x::SOuterKetBra) = SOuterKetBra(dagger(x.bra), dagger(x.ket)) dagger(x::SDagger) = x.obj basis(x::SDagger) = basis(x.obj) -function Base.show(io::IO, x::SDagger{AbstractOperator}) +function Base.show(io::IO, x::SDagger) print(io,x.obj) print(io,"†") end diff --git a/test/test_express_opt.jl b/test/test_express_opt.jl index e37a1bc..bb06d0a 100644 --- a/test/test_express_opt.jl +++ b/test/test_express_opt.jl @@ -35,4 +35,4 @@ op = N⊗X @test express(op*state) ≈ express(op)*express(state) @test express(op*state) ≈ express(F1⊗Z2) -#state = (3im*(2*dagger(Z1)+dagger(Y1))) * (3im*(2*X1+X2)) TODO predefined daggers and commutators +state = (3im*(2*dagger(Z1)+dagger(Y1))) * (3im*(2*X1+X2))