Skip to content

Commit

Permalink
deprecated DyadicChain symbol
Browse files Browse the repository at this point in the history
  • Loading branch information
chakravala committed Apr 28, 2024
1 parent 90ba554 commit 0e2bf7b
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 46 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
4 changes: 2 additions & 2 deletions src/Grassmann.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))))))
Expand Down
10 changes: 5 additions & 5 deletions src/composite.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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]
Expand All @@ -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!
Expand Down
40 changes: 12 additions & 28 deletions src/multivectors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
26 changes: 16 additions & 10 deletions src/products.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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) = ab
@inline times(a::DyadicChain,b::Chain) = ab
@inline times(a::DyadicChain,b::TensorTerm) = ab
@inline times(a::TensorGraded,b::DyadicChain) = ab
@inline times(a::DyadicChain,b::TensorNested) = ab
@inline times(a::TensorNested,b::DyadicChain) = ab
@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)))
Expand Down

0 comments on commit 0e2bf7b

Please sign in to comment.