Skip to content

Commit

Permalink
separated Poincare duality from Hodge complement
Browse files Browse the repository at this point in the history
  • Loading branch information
chakravala committed Oct 9, 2019
1 parent 39c3234 commit 49134d8
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 53 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.3.1"
version = "0.3.2"

[deps]
AbstractLattices = "398f06c4-4d28-53ec-89ca-5b2656b7603d"
Expand Down
93 changes: 49 additions & 44 deletions src/algebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -170,36 +170,39 @@ end

# Hodge star ★

const complementright =
const complementrighthodge =
const complementright = !

## complement

export complementleft, complementright,
export complementleft, complementright, , complementlefthodge, complementrighthodge

for side (:left,:right)
c = Symbol(:complement,side)
p = Symbol(:parity,side)
@eval @pure function $c(b::Basis{V,G,B}) where {V,G,B}
d = getbasis(V,complement(ndims(V),B,diffvars(V),hasinf(V)+hasorigin(V)))
mixedmode(V)<0 && throw(error("Complement for mixed tensors is undefined"))
typeof(V)<:Signature ? ($p(b) ? SBlade{V}(-value(d),d) : d) : SBlade{V}($p(b)*value(d),d)
end
for Blade MSB
@eval $c(b::$Blade) = value(b)0 ? value(b)*$c(basis(b)) : g_zero(vectorspace(b))
c,p = Symbol(:complement,side),Symbol(:parity,side)
h,pg = Symbol(c,:hodge),Symbol(p,:hodge)
for (c,p) ((c,p),(h,pg))
@eval @pure function $c(b::Basis{V,G,B}) where {V,G,B}
d = getbasis(V,complement(ndims(V),B,diffvars(V),$(ch ? 0 : :(hasinf(V)+hasorigin(V)))))
mixedmode(V)<0 && throw(error("Complement for mixed tensors is undefined"))
typeof(V)<:Signature ? ($p(b) ? SBlade{V}(-value(d),d) : d) : SBlade{V}($p(b)*value(d),d)
end
for B MSB
@eval $c(b::$B) = value(b)0 ? value(b)*$c(basis(b)) : g_zero(vectorspace(b))
end
end
end

@doc """
complementright(ω::TensorAlgebra)
Grassmann-Poincare-Hodge complement: ⋆ω = ω∗I
""" complementright
""" complementrighthodge

@doc """
complementleft(ω::TensorAlgebra)
Grassmann-Poincare left complement: ⋆'ω = I∗'ω
""" complementleft
""" complementlefthodge

## reverse

Expand Down Expand Up @@ -769,44 +772,46 @@ function generate_products(Field=Field,VEC=:mvec,MUL=:*,ADD=:+,SUB=:-,CONJ=:conj
end
end
for side (:left,:right)
c = Symbol(:complement,side)
p = Symbol(:parity,side)
for Chain MSC
@eval begin
function $c(b::$Chain{T,V,G}) where {T<:$Field,V,G}
mixedmode(V)<0 && throw(error("Complement for mixed tensors is undefined"))
$(insert_expr((:N,:ib,:D,:P),VEC)...)
out = zeros($VEC(N,G,T))
D = diffvars(V)
for k 1:binomial(N,G)
@inbounds val = b.v[k]
if val0
@inbounds p = $p(V,ib[k])
v = typeof(V)<:Signature ? (p ? $SUB(val) : val) : p*val
@inbounds setblade!(out,v,complement(N,ib[k],D,P),Dimension{N}())
c,p = Symbol(:complement,side),Symbol(:parity,side)
h,pg = Symbol(c,:hodge), Symbol(p,:hodge)
for (c,p) ((c,p),(h,pg))
for Chain MSC
@eval begin
function $c(b::$Chain{T,V,G}) where {T<:$Field,V,G}
mixedmode(V)<0 && throw(error("Complement for mixed tensors is undefined"))
$(insert_expr((:N,:ib,:D,:P),VEC)...)
out = zeros($VEC(N,G,T))
D = diffvars(V)
for k 1:binomial(N,G)
@inbounds val = b.v[k]
if val0
@inbounds p = $p(V,ib[k])
v = typeof(V)<:Signature ? (p ? $SUB(val) : val) : p*val
@inbounds setblade!(out,v,complement(N,ib[k],D,P),Dimension{N}())
end
end
return $Chain{T,V,N-G}(out)
end
return $Chain{T,V,N-G}(out)
end
end
end
@eval begin
function $c(m::MultiVector{T,V}) where {T<:$Field,V}
mixedmode(V)<0 && throw(error("Complement for mixed tensors is undefined"))
$(insert_expr((:N,:bs,:bn,:P),VEC)...)
out = zeros($VEC(N,T))
D = diffvars(V)
for g 1:N+1
ib = indexbasis(N,g-1)
@inbounds for i 1:bn[g]
@inbounds val = m.v[bs[g]+i]
if val0
v = typeof(V)<:Signature ? ($p(V,ib[i]) ? $SUB(val) : val) : $p(V,ib[i])*val
@inbounds setmulti!(out,v,complement(N,ib[i],D,P),Dimension{N}())
@eval begin
function $c(m::MultiVector{T,V}) where {T<:$Field,V}
mixedmode(V)<0 && throw(error("Complement for mixed tensors is undefined"))
$(insert_expr((:N,:bs,:bn,:P),VEC)...)
out = zeros($VEC(N,T))
D = diffvars(V)
for g 1:N+1
ib = indexbasis(N,g-1)
@inbounds for i 1:bn[g]
@inbounds val = m.v[bs[g]+i]
if val0
v = typeof(V)<:Signature ? ($p(V,ib[i]) ? $SUB(val) : val) : $p(V,ib[i])*val
@inbounds setmulti!(out,v,complement(N,ib[i],D,P),Dimension{N}())
end
end
end
return MultiVector{T,V}(out)
end
return MultiVector{T,V}(out)
end
end
end
Expand Down
33 changes: 25 additions & 8 deletions src/parity.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,41 @@ end

## complement parity

@pure parityright(V::Int,B,G,N=nothing) = isodd(V)isodd(B+Int((G+1)*G/2))
@pure parityrighthodge(V::Int,B,G,N=nothing) = isodd(V)parityright(V,B,G,N)
@pure paritylefthodge(V::Int,B,G,N) = (isodd(G) && iseven(N)) parityrightgrade(V,B,G,N)
@pure parityright(V::Int,B,G,N=nothing) = isodd(B+Int((G+1)*G/2))
@pure parityleft(V::Int,B,G,N) = (isodd(G) && iseven(N)) parityright(V,B,G,N)

for side (:left,:right)
p = Symbol(:parity,side)
pg = Symbol(p,:hodge)
@eval begin
@pure $p(V::Bits,B::Bits,N::Int) = $p(count_ones(V&B),sum(indices(B,N)),count_ones(B),N)
@pure $p(V::Bits,B::Bits,N::Int) = $p(0,sum(indices(B,N)),count_ones(B),N)
@pure $pg(V::Bits,B::Bits,N::Int) = $pg(count_ones(V&B),sum(indices(B,N)),count_ones(B),N)
@pure function $p(V::Signature,B,G=count_ones(B))
o = hasinf(V) && (hasorigin(V) ? iszero(B&UInt(2))&(!iszero(B&UInt(1))) : isodd(B))
b = B&(UInt(1)<<(ndims(V)-diffvars(V))-1)
$p(0,sum(indices(b,ndims(V))),count_ones(b),ndims(V)-diffvars(V))o
end
@pure function $pg(V::Signature,B,G=count_ones(B))
o = hasorigin(V) && (hasinf(V) ? iszero(B&UInt(1))&(!iszero(B&UInt(2))) : isodd(B))
b = B&(UInt(1)<<(ndims(V)-diffvars(V))-1)
$p(count_ones(value(V)&b),sum(indices(b,ndims(V))),count_ones(b),ndims(V)-diffvars(V))o
$pg(count_ones(value(V)&b),sum(indices(b,ndims(V))),count_ones(b),ndims(V)-diffvars(V))o
end
@pure function $p(V::DiagonalForm,B,G=count_ones(B))
ind = indices(B&(UInt(1)<<(ndims(V)-diffvars(V))-1),ndims(V))
$p(0,sum(ind),G,ndims(V)-diffvars(V)) ? -1 : 1
end
@pure function $pg(V::DiagonalForm,B,G=count_ones(B))
ind = indices(B&(UInt(1)<<(ndims(V)-diffvars(V))-1),ndims(V))
g = prod(V[ind])
$p(0,sum(ind),G,ndims(V)-diffvars(V)) ? -(g) : g
end
@pure $p(b::Basis{V,G,B}) where {V,G,B} = $p(V,B,G)
end
for p (p,pg)
@eval begin
@pure $p(b::Basis{V,G,B}) where {V,G,B} = $p(V,B,G)
end
end
end

Expand Down Expand Up @@ -74,7 +91,7 @@ end
else
false, A+B0 ? complement(N,C,D) : g_zero(UInt)
end
par = parityright(S,A,N)parityright(S,B,N)parityright(S,C,N)
par = parityrighthodge(S,A,N)parityrighthodge(S,B,N)parityrighthodge(S,C,N)
return (isodd(L*(L-grade(V)))parparity(N,S,α,β)pcc)::Bool, bas|Q, true, Z
else
return false, g_zero(UInt), false, Z
Expand All @@ -91,7 +108,7 @@ end
diffcheck(V,A,B) && (return false,g_zero(UInt),false,Z)
γ = complement(N,B,diffvars(V))
p,C,t = parityregressive(V,A,γ,Grade{true}())
return t ? pparityright(S,B,N) : p, C|Q, t, Z
return t ? pparityrighthodge(S,B,N) : p, C|Q, t, Z
end

@pure function parityinterior(V::M,a,b) where M<:Manifold{N} where N
Expand All @@ -114,7 +131,7 @@ end
A,B,Q,Z = symmetricmask(V,a,b)
if (count_ones(A&B)==0) && !(hasinf(M) && isodd(A) && isodd(B))
C = A B
return (parity(N,S,A,B)parityright(S,C,N)), complement(N,C,diffvars(V))|Q, true, Z
return (parity(N,S,A,B)parityrighthodge(S,C,N)), complement(N,C,diffvars(V))|Q, true, Z
else
return false, zero(Bits), false, Z
end
Expand All @@ -124,7 +141,7 @@ end
A,B,Q,Z = symmetricmask(V,a,b)
if (count_ones(A&B)==0) && !(hasinf(V) && isodd(A) && isodd(B))
C = A B
g = parityright(V,C,N)
g = parityrighthodge(V,C,N)
return parity(A,B,V) ? -(g) : g, complement(N,C,diffvars(V))|Q, true, Z
else
return 1, zero(Bits), false, Z
Expand Down

0 comments on commit 49134d8

Please sign in to comment.