diff --git a/Project.toml b/Project.toml index e625e6f..6f14abb 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "DirectSum" uuid = "22fd7b30-a8c0-5bf2-aabe-97783860d07c" authors = ["Michael Reed"] -version = "0.4.0" +version = "0.4.1" [deps] LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" diff --git a/src/DirectSum.jl b/src/DirectSum.jl index 5ac2a63..3bf5042 100644 --- a/src/DirectSum.jl +++ b/src/DirectSum.jl @@ -275,6 +275,16 @@ end d<0 ? typemax(Bits)-v : v end +@pure function symmetricsplit(V::M,a) where M<:Manifold + sm,dm = symmetricmask(V,a),diffmask(V) + mixedmode(V)<0 ? (sm&dm[1],sm&dm[2]) : sm +end + +@pure function symmetricmask(V::M,a) where M<:Manifold + d = diffmask(V) + a&(mixedmode(V)<0 ? |(d...) : d) +end + @pure function symmetricmask(V::M,a,b) where M<:Manifold d = diffmask(V) D = mixedmode(V)<0 ? |(d...) : d diff --git a/src/indices.jl b/src/indices.jl index 5a75203..1884319 100644 --- a/src/indices.jl +++ b/src/indices.jl @@ -186,6 +186,16 @@ end @inline printlabel(V::T,e::Bits,label::Bool,vec,cov,duo,dif) where T<:Manifold = printlabel(IOBuffer(),V,e,label,vec,cov,duo,dif) |> take! |> String +@pure function indexstring(V::M,D) where M<:Manifold + io = IOBuffer() + printlabel(io,V,D,true,"x","X","x","X") + String(take!(io)) +end + +@pure indexsymbol(V::M,D) where M<:Manifold = Symbol(indexstring(V,D)) + +@pure indexsplit(B,N) = [UInt(1)<<(k-1) for k ∈ indices(B,N)] + function indexparity!(ind::Vector{Int},s::M) where M<:Manifold k = 1 t = false diff --git a/src/operations.jl b/src/operations.jl index 6c171fb..07e87e2 100644 --- a/src/operations.jl +++ b/src/operations.jl @@ -71,13 +71,15 @@ end for op ∈ (:*,:∪) @eval begin @pure $op(a::T,::Q) where {T<:VectorBundle{N,M,S},Q<:VectorBundle{N,M,S}} where {N,M,S} = a - @pure $op(a::M,::Q) where Q<:SubManifold{Y,M,B} where Y where {M<:VectorBundle,A,B} = a - @pure $op(::T,b::M) where T<:SubManifold{X,M,A} where X where {M<:VectorBundle,A,B} = b - @pure $op(::T,::Q) where {T<:SubManifold{X,M,A} where X,Q<:SubManifold{Y,M,B} where Y} where {M,A,B} = SubManifold{M}(A|B) - @pure function $op(a::T,b::S) where {T<:VectorBundle{N1,M1,S1},S<:VectorBundle{N2,M2,S2}} where {N1,M1,S1,N2,M2,S2} + @pure $op(a::M,::SubManifold{Y,m,B}) where {Y,m,M<:VectorBundle,A,B} = a∪m + @pure $op(::SubManifold{X,m,A},b::M) where {X,m,M<:VectorBundle,A,B} = m∪b + @pure $op(::SubManifold{X,M,A} where X,::SubManifold{Y,M,B} where Y) where {M,A,B} = SubManifold{M}(A|B) + @pure function $op(a::T,b::S) where {T<:VectorBundle{N1,M1,S1,V1,d1},S<:VectorBundle{N2,M2,S2,V2,d2}} where {N1,M1,S1,V1,d1,N2,M2,S2,V2,d2} D1,O1,C1 = options_list(a) D2,O2,C2 = options_list(b) - if ((C1≠C2)&&(C1≥0)&&(C2≥0)) && a==b' + if (M1,S1) == (M2,S2) && (V1,d1) ≠ (V2,d2) + (T<:Signature ? Signature : DiagnoalManifold){max(N1,N2),M1,S1,max(V1,V2),max(d1,d2)}() + elseif ((C1≠C2)&&(C1≥0)&&(C2≥0)) && a==b' return C1>0 ? b⊕a : a⊕b elseif min(C1,C2)<0 && max(C1,C2)≥0 Y = C1<0 ? b⊆a : a⊆b @@ -92,18 +94,20 @@ for op ∈ (:*,:∪) end end -∪(x::T) where T<:Manifold = x -∪(a::A,b::B,c::C...) where {A<:Manifold,B<:Manifold,C<:Manifold} = ∪(a∪b,c...) +@pure ∪(x::T) where T<:Manifold = x +∪(a::A,b::B,c::C...) where {A<:Manifold,B<:Manifold,C<:Manifold} = ∪(a*b,c...) @pure ∩(a::T,::Q) where {T<:VectorBundle{N,M,S},Q<:VectorBundle{N,M,S}} where {N,M,S} = a @pure ∩(a::T,::S) where {T<:VectorBundle{N},S<:VectorBundle{N}} where N = V0 -@pure ∩(::M,b::Q) where Q<:SubManifold{Y,M,B} where Y where {M<:VectorBundle,A,B} = b -@pure ∩(a::T,::M) where T<:SubManifold{X,M,A} where X where {M<:VectorBundle,A,B} = a +#@pure ∩(::M,b::Q) where Q<:SubManifold{Y,M,B} where Y where {M<:VectorBundle,A,B} = b +#@pure ∩(a::T,::M) where T<:SubManifold{X,M,A} where X where {M<:VectorBundle,A,B} = a @pure ∩(::T,::Q) where {T<:SubManifold{X,M,A} where X,Q<:SubManifold{Y,M,B} where Y} where {M,A,B} = SubManifold{M}(A&B) -@pure function ∩(a::T,b::S) where {T<:VectorBundle{N1,M1,S1},S<:VectorBundle{N2,M2,S2}} where {N1,M1,S1,N2,M2,S2} +@pure function ∩(a::T,b::S) where {T<:VectorBundle{N1,M1,S1,V1,d1},S<:VectorBundle{N2,M2,S2,V2,d2}} where {N1,M1,S1,V1,d1,N2,M2,S2,V2,d2} D1,O1,C1 = options_list(a) D2,O2,C2 = options_list(b) - if ((C1≠C2)&&(C1≥0)&&(C2≥0)) + if (M1,S1) == (M2,S2) && (V1,d1) ≠ (V2,d2) + (T<:Signature ? Signature : DiagnoalManifold){min(N1,N2),M1,S1,min(V1,V2),min(d1,d2)}() + elseif ((C1≠C2)&&(C1≥0)&&(C2≥0)) return V0 elseif min(C1,C2)<0 && max(C1,C2)≥0 Y = C1<0 @@ -122,10 +126,12 @@ end @pure ⊆(::M,b::Q) where Q<:SubManifold{Y,M,B} where {M<:VectorBundle,A,B,Y} = ndims(M) == Y @pure ⊆(a::T,::M) where T<:SubManifold{X,M,A} where X where {M<:VectorBundle,A,B} = true @pure ⊆(::T,::Q) where {T<:SubManifold{X,M,A},Q<:SubManifold{Y,M,B} where Y} where {M,A,B,X} = count_ones(A&B) == X -@pure function ⊆(a::T,b::S) where {T<:VectorBundle{N1,M1,S1},S<:VectorBundle{N2,M2,S2}} where {N1,M1,S1,N2,M2,S2} +@pure function ⊆(a::T,b::S) where {T<:VectorBundle{N1,M1,S1,V1,d1},S<:VectorBundle{N2,M2,S2,V2,d2}} where {N1,M1,S1,V1,d1,N2,M2,S2,V2,d2} D1,O1,C1 = options_list(a) D2,O2,C2 = options_list(b) - if ((C1≠C2)&&(C1≥0)&&(C2≥0)) || ((C1<0)&&(C2≥0)) + if (M1,S1) == (M2,S2) && (V1,d1) ≠ (V2,d2) + V1 ≤ V2 && d1 ≤ d2 + elseif ((C1≠C2)&&(C1≥0)&&(C2≥0)) || ((C1<0)&&(C2≥0)) return false elseif C2<0 && C1≥0 return (C1>0 ? a'⊕a : a⊕a') == b