Skip to content

Commit

Permalink
Change the result of the multiplication of two identical fermion oper…
Browse files Browse the repository at this point in the history
…ators from 0 to the product with zero coefficient so that type stability can be preserved.
  • Loading branch information
waltergu committed Oct 20, 2023
1 parent d8451b7 commit f3d829b
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 19 deletions.
8 changes: 4 additions & 4 deletions docs/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -756,9 +756,9 @@ uuid = "6462fe0b-24de-5631-8697-dd941f90decc"

[[deps.SortingAlgorithms]]
deps = ["DataStructures"]
git-tree-sha1 = "c60ec5c62180f27efea3ba2908480f8055e17cee"
git-tree-sha1 = "5165dfb9fd131cf0c6957a3a7605dede376e7b63"
uuid = "a2af1166-a08f-5f64-846c-94a0d3cef48c"
version = "1.1.1"
version = "1.2.0"

[[deps.SparseArrays]]
deps = ["Libdl", "LinearAlgebra", "Random", "Serialization", "SuiteSparse_jll"]
Expand Down Expand Up @@ -831,9 +831,9 @@ deps = ["InteractiveUtils", "Logging", "Random", "Serialization"]
uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[[deps.TranscodingStreams]]
git-tree-sha1 = "7c9196c8c83802d7b8ca7a6551a0236edd3bf731"
git-tree-sha1 = "49cbf7c74fafaed4c529d47d48c8f7da6a19eb75"
uuid = "3bb67fe8-82b1-5028-8e26-92a6c54297fa"
version = "0.10.0"
version = "0.10.1"
weakdeps = ["Random", "Test"]

[deps.TranscodingStreams.extensions]
Expand Down
9 changes: 5 additions & 4 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ using QuantumLattices

makedocs(
format= Documenter.HTML(
prettyurls= get(ENV, "CI", "false") == "true",
canonical= "https://quantum-many-body.github.io/QuantumLattices.jl/latest/",
assets= ["assets/favicon.ico"],
analytics= "UA-89508993-1",
prettyurls = get(ENV, "CI", "false") == "true",
canonical = "https://quantum-many-body.github.io/QuantumLattices.jl/latest/",
assets = ["assets/favicon.ico"],
analytics = "UA-89508993-1",
size_threshold_warn = 204800,
),
sitename= "QuantumLattices.jl",
pages= [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -521,11 +521,9 @@ Operators with 2 Operator
julia> another = Operator(2, FID{:f}(1, 1//2, 1)) + Operator(3, FID{:f}(1, 1//2, 2));
julia> ops * another
Operators with 4 Operator
Operators with 2 Operator
Operator(6, FID{:f}(1, 1//2, 1), FID{:f}(1, 1//2, 2))
Operator(6, FID{:f}(1, 1//2, 2), FID{:f}(1, 1//2, 1))
Operator(9, FID{:f}(1, 1//2, 2), FID{:f}(1, 1//2, 2))
Operator(4, FID{:f}(1, 1//2, 1), FID{:f}(1, 1//2, 1))
julia> 2 * ops
Operators with 2 Operator
Expand All @@ -537,7 +535,7 @@ Operators with 2 Operator
Operator(6, FID{:f}(1, 1//2, 2))
Operator(4, FID{:f}(1, 1//2, 1))
```
It is noted that in the result, the distributive law automatically applies.
It is noted that in the result, the distributive law automatically applies. Besides, the fermion operator relation $c^2=c\dagger^2=0$ is also used.

As is usual, the Hermitian conjugate of an [`Operators`](@ref) can be obtained by the adjoint operator:
```jldoctest
Expand Down
5 changes: 3 additions & 2 deletions src/QuantumSystems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,9 @@ end
Get the multiplication of two fermionic Fock operators.
"""
const block = quote
rank(f₁)>0 && rank(f₂)>0 && f₁[end]==f₂[1] && return 0
return invoke(*, Tuple{OperatorProd, OperatorProd}, f₁, f₂)
result = invoke(*, Tuple{OperatorProd, OperatorProd}, f₁, f₂)
rank(f₁)>0 && rank(f₂)>0 && f₁[end]==f₂[1] && return replace(result, value=zero(valtype(result)))
return result
end
@eval @inline Base.:*(f₁::Operator{<:Number, <:ID{FID{:f}}}, f₂::Operator{<:Number, <:ID{FID{:f}}}) = $block
@eval @inline Base.:*(f₁::Operator{<:Number, <:ID{Index{Int, <:FID{:f}}}}, f₂::Operator{<:Number, <:ID{Index{Int, <:FID{:f}}}}) = $block
Expand Down
8 changes: 4 additions & 4 deletions test/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -656,9 +656,9 @@ uuid = "6462fe0b-24de-5631-8697-dd941f90decc"

[[deps.SortingAlgorithms]]
deps = ["DataStructures"]
git-tree-sha1 = "c60ec5c62180f27efea3ba2908480f8055e17cee"
git-tree-sha1 = "5165dfb9fd131cf0c6957a3a7605dede376e7b63"
uuid = "a2af1166-a08f-5f64-846c-94a0d3cef48c"
version = "1.1.1"
version = "1.2.0"

[[deps.SparseArrays]]
deps = ["Libdl", "LinearAlgebra", "Random", "Serialization", "SuiteSparse_jll"]
Expand Down Expand Up @@ -722,9 +722,9 @@ deps = ["InteractiveUtils", "Logging", "Random", "Serialization"]
uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[[deps.TranscodingStreams]]
git-tree-sha1 = "7c9196c8c83802d7b8ca7a6551a0236edd3bf731"
git-tree-sha1 = "49cbf7c74fafaed4c529d47d48c8f7da6a19eb75"
uuid = "3bb67fe8-82b1-5028-8e26-92a6c54297fa"
version = "0.10.0"
version = "0.10.1"
weakdeps = ["Random", "Test"]

[deps.TranscodingStreams.extensions]
Expand Down
2 changes: 1 addition & 1 deletion test/QuantumSystems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ end

op₁ = Operator(1.5, id₁, id₂)
op₂ = Operator(2.0, id₂, id₁)
@test op₁*op₂ == 0
@test op₁*op₂ == Operator(0.0, id₁, id₂, id₂, id₁)

op₁ = Operator(1.5, id₁, id₂)
op₂ = Operator(2.0, id₁, id₂)
Expand Down

0 comments on commit f3d829b

Please sign in to comment.