From 0e2bf7bdf50386d4fe69c42c042cd51cd4e54e77 Mon Sep 17 00:00:00 2001 From: Michael Reed <18372368+chakravala@users.noreply.github.com> Date: Sat, 27 Apr 2024 22:47:03 -0400 Subject: [PATCH] deprecated DyadicChain symbol --- Project.toml | 2 +- src/Grassmann.jl | 4 ++-- src/composite.jl | 10 +++++----- src/multivectors.jl | 40 ++++++++++++---------------------------- src/products.jl | 26 ++++++++++++++++---------- 5 files changed, 36 insertions(+), 46 deletions(-) diff --git a/Project.toml b/Project.toml index eaa4218..7ef2514 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "Grassmann" uuid = "4df31cd9-4c27-5bea-88d0-e6a7146666d8" authors = ["Michael Reed"] -version = "0.8.18" +version = "0.8.19" [deps] AbstractTensors = "a8e43f4a-99b7-5565-8bf1-0165161caaea" diff --git a/src/Grassmann.jl b/src/Grassmann.jl index 1fb79cc..6c37384 100644 --- a/src/Grassmann.jl +++ b/src/Grassmann.jl @@ -566,9 +566,9 @@ function __init__() end=# @require StaticArrays="90137ffa-7385-5640-81b9-e52037218182" begin StaticArrays.SMatrix(m::Chain{V,G,<:Chain{W,G}}) where {V,W,G} = StaticArrays.SMatrix{binomial(mdims(W),G),binomial(mdims(V),G)}(vcat(value.(value(m))...)) - DyadicChain(m::StaticArrays.SMatrix{N,N}) where N = Chain{Submanifold(N),1}(m) + Chain(m::StaticArrays.SMatrix{N,N}) where N = Chain{Submanifold(N),1}(m) Chain{V,G}(m::StaticArrays.SMatrix{N,N}) where {V,G,N} = Chain{V,G}(Chain{V,G}.(getindex.(Ref(m),:,StaticArrays.SVector{N}(1:N)))) - Chain{V,G,Chain{W,G}}(m::StaticArrays.SMatrix{M,N}) where {V,W,G,M,N} = Chain{V,G}(Chain{W,G}.(getindex.(Ref(m),:,StaticArrays.SVector{N}(1:N)))) + Chain{V,G,<:Chain{W,G}}(m::StaticArrays.SMatrix{M,N}) where {V,W,G,M,N} = Chain{V,G}(Chain{W,G}.(getindex.(Ref(m),:,StaticArrays.SVector{N}(1:N)))) #Base.log(A::Chain{V,G,<:Chain{V,G}}) where {V,G} = Chain{V,G}(log(StaticArrays.SMatrix(A))) LinearAlgebra.eigvals(A::Chain{V,G,<:Chain{V,G}}) where {V,G} = Chain(Values{binomial(mdims(V),G)}(LinearAlgebra.eigvals(StaticArrays.SMatrix(A)))) LinearAlgebra.eigvecs(A::Chain{V,G,<:Chain{V,G}}) where {V,G} = Chain(Chain.(Values{binomial(mdims(A),G)}.(getindex.(Ref(LinearAlgebra.eigvecs(StaticArrays.SMatrix(A))),:,list(1,binomial(mdims(A),G)))))) diff --git a/src/composite.jl b/src/composite.jl index 8e9a8bd..3ec5d25 100644 --- a/src/composite.jl +++ b/src/composite.jl @@ -216,10 +216,10 @@ function Base.exp(t::T,::Val{hint}) where T<:TensorGraded{V} where {V,hint} end end -@inline Base.expm1(A::DyadicChain) = exp(A)-I -@inline Base.exp(A::DyadicChain{V,G,T,1}) where {V,G,T} = Chain{V,G}(Values(Chain{V,G}(exp(A[1][1])))) +@inline Base.expm1(A::Chain{V,G,<:Chain{V,G}}) where {V,G} = exp(A)-I +@inline Base.exp(A::Chain{V,G,<:Chain{V,G},1}) where {V,G} = Chain{V,G}(Values(Chain{V,G}(exp(A[1][1])))) -@inline function Base.exp(A::DyadicChain{V,G,<:Real,2}) where {V,G} +@inline function Base.exp(A::Chain{V,G,Chain{V,G,<:Real,2},2}) where {V,G} T = typeof(exp(zero(valuetype(A)))) @inbounds a = A[1][1] @inbounds c = A[1][2] @@ -246,7 +246,7 @@ end Chain{V,G}(Chain{V,G}(m11, m21), Chain{V,G}(m12, m22)) end -@inline function Base.exp(A::DyadicChain{V,G,<:Complex,2}) where {V,G} +@inline function Base.exp(A::Chain{V,G,Chain{V,G,<:Complex,2},2}) where {V,G} T = typeof(exp(zero(valuetype(A)))) @inbounds a = A[1][1] @inbounds c = A[1][2] @@ -266,7 +266,7 @@ end # Adapted from implementation in Base; algorithm from # Higham, "Functions of Matrices: Theory and Computation", SIAM, 2008 -function Base.exp(_A::DyadicChain{W,G,T,N}) where {W,G,T,N} +function Base.exp(_A::Chain{W,G,Chain{W,G,T,N},N}) where {W,G,T,N} S = typeof((zero(T)*zero(T) + zero(T)*zero(T))/one(T)) A = Chain{W,G}(map.(S,value(_A))) # omitted: matrix balancing, i.e., LAPACK.gebal! diff --git a/src/multivectors.jl b/src/multivectors.jl index 7887595..ab2f605 100644 --- a/src/multivectors.jl +++ b/src/multivectors.jl @@ -25,13 +25,6 @@ import Leibniz: grade, antigrade, showvalue, basis, order export TensorNested abstract type TensorNested{V,T} <: Manifold{V,T} end -for op ∈ (:(Base.:+),:(Base.:-)) - @eval begin - $op(a::A,b::B) where {A<:TensorNested,B<:TensorAlgebra} = $op(DyadicChain(a),b) - $op(a::A,b::B) where {A<:TensorAlgebra,B<:TensorNested} = $op(a,DyadicChain(b)) - end -end - # symbolic print types import Leibniz: Fields, parval, mixed, mvecs, svecs, spinsum, spinsum_set @@ -94,26 +87,21 @@ Chain(v::Chain{V,G,𝕂}) where {V,G,𝕂} = v #Chain{𝕂}(v::Chain{V,G}) where {V,G,𝕂} = Chain{V,G}(Values{binomial(mdims(V),G),𝕂}(v.v)) @inline (::Type{T})(x...) where {T<:Chain} = T(x) -DyadicProduct{V,W,G,T,N} = Chain{V,G,Chain{W,G,T,N},N} -DyadicChain{V,G,T,N} = DyadicProduct{V,V,G,T,N} -#TriadicProduct{V,W,G,T,N} = Chain{V,G,DyadicChain{W,G,T,N},N} -#DyadicChain{V,G,T,N} = Chain{V,G,Chain{V,G,T,N},N} -#TriadicChain{V,G,T,N,M} = Chain{V,G,DyadicChain{V,1,T,M},N} +#Simplex{V,W,T<:GradedVector{W},N} = Chain{V,1,T,N} +Simplex{V,T<:GradedVector,N} = Chain{V,1,T,N} Base.Matrix(m::Chain{V,G,<:TensorGraded{W,G}}) where {V,W,G} = hcat(value.(Chain.(value(m)))...) Base.Matrix(m::Chain{V,G,<:Chain{W,G}}) where {V,W,G} = hcat(value.(value(m))...) +Chain(m::Matrix) = DyadicChain{Submanifold(size(m)[1])}(m) Chain{V}(m::Matrix) where V = Chain{V,1}(m) function Chain{V,G}(m::Matrix) where {V,G} N = size(m)[2] Chain{V,G,Chain{N≠mdims(V) ? Submanifold(N) : V,G}}(m) end -Chain{V,G,Chain{W,G}}(m::Matrix) where {V,W,G} = Chain{V,G}(Chain{W,G}.(getindex.(Ref(m),:,list(1,size(m)[2])))) -DyadicChain{V,G}(m::Matrix) where {V,G} = Chain{V,G}(Chain{V,G}.(getindex.(Ref(m),:,list(1,size(m)[2])))) -DyadicChain{V}(m::Matrix) where V = DyadicChain{V,1}(m) -DyadicChain(m::Matrix) = DyadicChain{Submanifold(size(m)[1])}(m) -Base.log(A::DyadicChain{V,G}) where {V,G} = DyadicChain{V,G}(log(Matrix(A))) +Chain{V,G,<:Chain{W,G}}(m::Matrix) where {V,W,G} = Chain{V,G}(Chain{W,G}.(getindex.(Ref(m),:,list(1,size(m)[2])))) +Base.log(A::Chain{V,G,<:Chain{V,G}}) where {V,G} = Chain{V,G,Chain{V,G}}(log(Matrix(A))) -export Chain, DyadicChain, TriadicChain, DyadicProduct +export Chain, Simplex getindex(m::Chain,i::Int) = m.v[i] getindex(m::Chain,i::UnitRange{Int}) = m.v[i] getindex(m::Chain,i::T) where T<:AbstractVector = m.v[i] @@ -1009,11 +997,10 @@ Leibniz.extend_parnot(Projector) show(io::IO,P::Proj{V,T,Λ}) where {V,T,Λ<:Real} = print(io,isone(P.λ) ? "" : P.λ,"Proj(",P.v,")") show(io::IO,P::Proj{V,T,Λ}) where {V,T,Λ} = print(io,"(",P.λ,")Proj(",P.v,")") -DyadicChain{V,1,T}(P::Proj{V,T}) where {V,T} = outer(P.v*P.λ,P.v) -DyadicChain{V,1,T}(P::Proj{V,T}) where {V,T<:Chain{V,1,<:Chain}} = sum(outer.(value(P.v).*value(P.λ),P.v)) -#DyadicChain{V,T}(P::Proj{V,T}) where {V,T<:Chain{V,1,<:TensorNested}} = sum(DyadicChain.(value(P.v))) -DyadicChain{V}(P::Proj{V,T}) where {V,T} = DyadicChain{V,1,T}(P) -DyadicChain(P::Proj{V,T}) where {V,T} = DyadicChain{V,1,T}(P) +#Chain{V}(P::Proj{V,T}) where {V,T<:Chain{V,1,<:TensorNested}} = sum(Chain.(value(P.v))) +Chain{V}(P::Proj{V,T}) where {V,T<:Simplex{V}} = sum(outer.(value(P.v).*value(P.λ),P.v)) +Chain{V}(P::Proj{V}) where V = outer(P.v*P.λ,P.v) +Chain(P::Proj{V}) where V = Chain{V}(P) struct Dyadic{V,X,Y} <: TensorNested{V,X} x::X @@ -1032,11 +1019,8 @@ getindex(P::Dyadic,i::Int,j::Int) = P.x[i]*P.y[j] show(io::IO,P::Dyadic) = print(io,"(",P.x,")⊗(",P.y,")") -DyadicChain(P::Dyadic{V}) where V = DyadicProduct{V}(P) -#DyadicChain{V}(P::Dyadic{V}) where V = outer(P.x,P.y) -DyadicChain{V}(P::Dyadic{V}) where V = DyadicProduct{V}(p) -DyadicProduct(P::Dyadic{V}) where V = DyadicProduct{V}(P) -DyadicProduct{V}(P::Dyadic{V}) where V = outer(P.x,P.y) +Chain{V}(P::Dyadic{V}) where V = outer(P.x,P.y) +Chain(P::Dyadic{V}) where V = Chain{V}(P) ## Generic diff --git a/src/products.jl b/src/products.jl index 4de00e0..2cb3bee 100644 --- a/src/products.jl +++ b/src/products.jl @@ -766,20 +766,26 @@ minus(a::TensorNested,b::TensorNested) = a+(-b) @inline times(a::TensorGraded{V,0},b::Proj{V,<:Chain{V,1,<:TensorNested}}) where V = Proj{V}(a*b.v) @inline times(a::Proj{V,<:Chain{V,1,<:TensorNested}},b::TensorGraded{V,0}) where V = Proj{V}(a.v*b) -@inline times(a::DyadicChain,b::DyadicChain) = a⋅b -@inline times(a::DyadicChain,b::Chain) = a⋅b -@inline times(a::DyadicChain,b::TensorTerm) = a⋅b -@inline times(a::TensorGraded,b::DyadicChain) = a⋅b -@inline times(a::DyadicChain,b::TensorNested) = a⋅b -@inline times(a::TensorNested,b::DyadicChain) = a⋅b +@inline times(a::Chain,b::Chain{V,G,<:Chain{V,G}} where {V,G}) = contraction(a,b) +@inline times(a::Chain{V,G,<:Chain{V,G}} where {V,G},b::Chain) = contraction(a,b) +@inline times(a::Chain{V,G,<:Chain{V,G}} where {V,G},b::TensorTerm) = contraction(a,b) +@inline times(a::TensorGraded,b::Chain{V,G,<:Chain{V,G}} where {V,G}) = contraction(a,b) +@inline times(a::Chain{V,G,<:Chain{V,G}} where {V,G},b::TensorNested) = contraction(a,b) +@inline times(a::TensorNested,b::Chain{V,G,<:Chain{V,G}} where {V,G}) = contraction(a,b) # dyadic identity element -Base.:+(t::LinearAlgebra.UniformScaling,g::TensorNested) = t+DyadicChain(g) -Base.:+(g::TensorNested,t::LinearAlgebra.UniformScaling) = DyadicChain(g)+t +for op ∈ (:(Base.:+),:(Base.:-)) + for tensor ∈ (:Projector,:Dyadic) + @eval begin + $op(a::A,b::B) where {A<:$tensor,B<:TensorAlgebra} = $op(Chain(a),b) + $op(a::A,b::B) where {A<:TensorAlgebra,B<:$tensor} = $op(a,Chain(b)) + $op(t::LinearAlgebra.UniformScaling,g::$tensor) = $op(t,Chain(g)) + $op(g::$tensor,t::LinearAlgebra.UniformScaling) = $op(Chain(g),t) + end + end +end Base.:+(g::Chain{V,1,<:Chain{V,1}},t::LinearAlgebra.UniformScaling) where V = t+g -Base.:-(t::LinearAlgebra.UniformScaling,g::TensorNested) = t-DyadicChain(g) -Base.:-(g::TensorNested,t::LinearAlgebra.UniformScaling) = DyadicChain(g)-t @generated Base.:+(t::LinearAlgebra.UniformScaling{Bool},g::Chain{V,1,<:Chain{V,1}}) where V = :(Chain{V,1}($(getalgebra(V).b[Grassmann.list(2,mdims(V)+1)]).+value(g))) @generated Base.:+(t::LinearAlgebra.UniformScaling,g::Chain{V,1,<:Chain{V,1}}) where V = :(Chain{V,1}(t.λ*$(getalgebra(V).b[Grassmann.list(2,mdims(V)+1)]).+value(g))) @generated Base.:-(t::LinearAlgebra.UniformScaling{Bool},g::Chain{V,1,<:Chain{V,1}}) where V = :(Chain{V,1}($(getalgebra(V).b[Grassmann.list(2,mdims(V)+1)]).-value(g)))