Skip to content

Commit

Permalink
extended interior syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
chakravala committed Oct 19, 2024
1 parent 36ca4c5 commit a6badb9
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 59 deletions.
4 changes: 2 additions & 2 deletions src/algebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
import Base: +, -, *, ^, /, //, inv, <, >, <<, >>, >>>
import AbstractTensors: , , , , , , , , , , , , , rem, div, TAG, SUB
import AbstractTensors: plus, minus, times, contraction, equal, wedgedot, veedot
import AbstractTensors: pseudosandwich, antisandwich, antidot
import AbstractTensors: pseudosandwich, antisandwich, cosandwich, antidot, codot
import Leibniz: diffcheck, diffmode, symmetricsplit
import Leibniz: loworder, isnull, Field, ExprField
const Sym,SymField = :AbstractTensors,Any

export , , , , , , wedgedot, veedot, , , , , , ,
export , sandwich, pseudosandwich, antisandwich
export , sandwich, pseudosandwich, antisandwich, cosandwich

if VERSION >= v"1.10.0"; @eval begin
import AbstractTensors.$(Symbol(""))
Expand Down
3 changes: 3 additions & 0 deletions src/composite.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
export exph, log_fast, logh_fast, pseudoexp, pseudolog, pseudometric, pseudodot, @pseudo
export pseudoabs, pseudoabs2, pseudosqrt, pseudocbrt, pseudoinv, pseudoscalar
export pseudocos, pseudosin, pseudotan, pseudocosh, pseudosinh, pseudotanh
export coabs, coabs2, cosqrt, cocbrt, coinv, coscalar, coexp, colog, cometric, codot, @co
export cocos, cosin, cotan, cocosh, cosinh, cotanh

export vandermonde, volumes, detsimplex, submesh

## exponential & logarithm function
Expand Down
24 changes: 21 additions & 3 deletions src/forms.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# This file is part of Grassmann.jl. It is licensed under the AGPL license
# Grassmann Copyright (C) 2019 Michael Reed

export TensorNested, Projector, Dyadic, Proj, outer, InducedMetric
export TensorNested, Projector, Dyadic, Proj, outer
export DiagonalOperator, TensorOperator, Endomorphism, Outermorphism, outermorphism
export operator, gradedoperator, evenoperator, oddoperator, MetricTensor, metrictensor
export operator, gradedoperator, evenoperator, oddoperator
export MetricTensor, metrictensor, metricextensor, InducedMetric

## conversions

Expand Down Expand Up @@ -928,6 +929,7 @@ MetricTensor(b...) = MetricTensor(b)

@pure Manifold(::Type{T}) where T<:MetricTensor = T()

construct_cache(:MetricTensor)
@pure metrictensor(b::Submanifold{V}) where V = isbasis(b) ? metrictensor(V) : TensorOperator(map(b,b(value(metrictensor(V)))))
@pure metrictensor(V,G) = compound(metrictensor(V),G)
@pure function metrictensor(V::MetricTensor{N,M,S} where N) where {M,S}
Expand All @@ -954,7 +956,7 @@ end
@inline getindex(vs::MetricTensor,i::UnitRange{Int}) = [getindex(vs,j) for j i]
@inline getindex(vs::MetricTensor{N,M,S} where M,i::Colon) where {N,S} = Vector(value(metrictensor(vs)))

@pure Signature(V::MetricTensor{N,M}) where {N,M} = Signature{N,M,UInt(0)}()
@pure Signature(V::MetricTensor{N,M,S,F,D}) where {N,M,S,F,D} = Signature{N,M,UInt(0),F,D}()

# anything array-like gets summarized e.g. 10-element Array{Int64,1}
Base.summary(io::IO, a::MetricTensor) = Base.array_summary(io, a, _axes(metrictensor(a)))
Expand All @@ -974,6 +976,22 @@ end

isdiag(::MetricTensor) = false

function DirectSum.TensorBundle(b::Submanifold{V}) where V
if isbasis(b)
TensorBundle(V)
elseif typeof(V) <: Int
Signature(mdims(b))
elseif typeof(V) <: Signature
Signature(b)
elseif typeof(V) <: DiagonalForm
M = options(V)
DiagonalForm{mdims(b),M,DirectSum.diagsig(M,Values(DirectSum.diagonalform(V)[indices(b)]...)),diffvars(V),diffmode(V)}()
elseif typeof(V) <: MetricTensor
M = options(V)
MetricTensor{mdims(b),M,metricsig(M,value.(value(value(metrictensor(b))))),diffvars(V),diffmode(V)}()
end
end

# InducedMetric

struct InducedMetric end
Expand Down
126 changes: 72 additions & 54 deletions src/parity.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,20 @@ end
p,C,t,Z = _parityregressive(V,A,B)
return p ? -1 : 1, C, t, Z
end
@pure function parityregressive(::M,A,B) where M<:Manifold{V} where V
@pure function parityregressive(V::M,A,B) where M<:Manifold
parityregressivenum(Signature(V),A,B)
end

@pure function parityinterior(V::Int,a,b)
A,B,Q,Z = symmetricmask(V,a,b)
diffcheck(V,A,B) && (return false,Zero(UInt),false,Z)
diffcheck(V,A,B) && (return lim ? (Values{0,Tuple{UInt,Int}}(),Z) : (1,Zero(UInt),false,Z))
p,C,t = parityregressive(V,A,complement(V,B,diffvars(V)),Val(true))
t ? (pparityright(0,sum(indices(B,V)),count_ones(B)) ? -1 : 1) : 1, C|Q, t, Z
end

#=@pure function parityinterior(V::Signature{N,M,S},a,b) where {N,M,S}
A,B,Q,Z = symmetricmask(V,a,b)
diffcheck(V,A,B) && (return false,Zero(UInt),false,Z)
diffcheck(V,A,B) && (return 1,Zero(UInt),false,Z)
p,C,t = parityregressive(V,A,complement(N,B,diffvars(V)),Val{true}())
return t ? p⊻parityrighthodge(S,B,N) : p, C|Q, t, Z
end=#
Expand Down Expand Up @@ -107,7 +107,7 @@ end
bs,bg = (),()
for i list(1,diag ? 1 : gdims(grade(V),G))
if (!isnull(g[i])) && !diffcheck2(V,A,bas[i])
p,C,t = parityregressive(Signature(W),A,complement(N,bas[i],diffvars(V)),Val{true}())
p,C,t = parityregressive(Signature(V),A,complement(N,bas[i],diffvars(V)),Val{true}())
CQ,tout = C|Q,tout|t
if t
ggg = (pparityright(0,sum(indices(bas[i],N)),G)) ? field ? :(-($(g[i]))) : -(g[i]) : g[i]
Expand Down Expand Up @@ -149,7 +149,7 @@ end
else
value(metrictensor(V,G))[bladeindex(mdims(V),C)]
end
parity(Signature(W),A,B) ? fieldneg(g) : g
parity(Signature(V),A,B) ? fieldneg(g) : g
end

function parityseq(V,B)
Expand Down Expand Up @@ -362,63 +362,81 @@ end

### parity product caches

function interior(V,a,b,c::Val{lim},d::Val{field}=Val(false)) where {lim,field}
lim||field ? parityinterior(V,a,b,c,d) : interior(V,a,b)
end

for par (:conformal,:regressive,:interior)
calc = par:regressive ? Symbol(:parity,par) : :parityregressivenum
T = Tuple{Any,UInt,Bool,UInt}
extra = Symbol(par,:_extra)
cache = Symbol(par,:_cache)
@eval begin
const $cache = Dict{UInt,Vector{Dict{UInt,Vector{Vector{$T}}}}}[]
const $extra = Dict{UInt,Vector{Dict{UInt,Dict{UInt,Dict{UInt,$T}}}}}[]
@pure function $par(V,a,b)::$T
M,s = DirectSum.supermanifold(V),metric(V)
n,m,S = mdims(M),DirectSum.options(M),metric(M)
m1 = m+1
if n > sparse_limit
N = n-sparse_limit
for k length($extra)+1:N
push!($extra,Dict{UInt,Vector{Dict{UInt,Dict{UInt,Dict{UInt,$T}}}}}())
end
if !haskey($extra[N],S)
push!($extra[N],S=>Dict{UInt,Dict{UInt,Dict{UInt,$T}}}[])
@pure interior(V::Submanifold,a,b,c,d) = interior(TensorBundle(V),a,b,c,d)
@pure interior(V,a,b,c::Val=Val(false)) = interior(V,a,b,c,Val(false))
@pure interior(V,a,b,c::Val{true},d::Val=Val(false)) = parityinterior(V,a,b,c,d)
@pure interior(a::Submanifold{V,G,B},b::Submanifold{V,L,C},c::Val=Val(false)) where {V,G,B,L,C} = interior(V,UInt(a),UInt(b),c,Val(false))
@pure interior(a::Submanifold{V,G,B},b::Submanifold{V,L,C},c::Val,d::Val{false}) where {V,G,B,L,C} = interior(V,UInt(a),UInt(b),c,d)
interior(a::Submanifold{V,G,B},b::Submanifold{V,L,C},c::Val,d::Val{true}) where {V,G,B,L,C} = interior(V,UInt(a),UInt(b),c,d)
@pure regressive(a::Submanifold{V,G,B},b::Submanifold{V,L,C}) where {V,G,B,L,C} = regressive(V,UInt(a),UInt(b))

function construct_cache(typ::Symbol)
for par (:regressive,:interior)
noreg = par:regressive
for field (noreg ? (true,false) : (false,))
(!noreg) && typ :Signature && continue
calc = noreg ? Symbol(:parity,par) : :parityregressivenum
T = Tuple{Any,UInt,Bool,UInt}
extra = noreg ? Symbol(par,(field ? (:_field,) : ())...,:_,typ,:_extra) : Symbol(par,:_extra)
cache = noreg ? Symbol(par,(field ? (:_field,) : ())...,:_,typ,:_cache) : Symbol(par,:_cache)
quot = quote
M = $(noreg ? :V : :(Signature(V)))
n,m,S = mdims(M),DirectSum.options(M),metric(M)
m1 = m+1
if n > sparse_limit
N = n-sparse_limit
for k length($extra)+1:N
push!($extra,Dict{UInt,Vector{Dict{UInt,Dict{UInt,$T}}}}())
end
if !haskey($extra[N],S)
push!($extra[N],S=>Dict{UInt,Dict{UInt,$T}}[])
end
for k length($extra[N][S])+1:m1
@inbounds push!($extra[N][S],Dict{UInt,Dict{UInt,$T}}())
end
@inbounds !haskey($extra[N][S][m1],a) && push!($extra[N][S][m1],a=>Dict{UInt,$T}())
@inbounds !haskey($extra[N][S][m1][a],b) && push!($extra[N][S][m1][a],b=>$calc(M,a,b,$((noreg ? (:c,:d) : ())...)))
@inbounds $extra[N][S][m1][a][b]
elseif n==0
$calc(M,a,b,$((noreg ? (:c,:d) : ())...))
else
a1 = a+1
for k length($cache)+1:n
push!($cache,Dict{UInt,Vector{Vector{$T}}}())
end
if !haskey($cache[n],S)
push!($cache[n],S=>Vector{Vector{$T}}[])
end
@inbounds for k length($cache[n][S])+1:m1
@inbounds push!($cache[n][S],Vector{Vector{$T}}())
end
@inbounds for k length($cache[n][S][m1]):a
@inbounds push!($cache[n][S][m1],$T[])
end
@inbounds for k length($cache[n][S][m1][a1]):b
@inbounds push!($cache[n][S][m1][a1],$calc(M,a,k,$((noreg ? (:c,:d) : ())...)))
end
@inbounds $cache[n][S][m1][a1][b+1]
end
for k length($extra[N][S])+1:m1
@inbounds push!($extra[N][S],Dict{UInt,Dict{UInt,Dict{UInt,$T}}}())
end
@eval begin
global const $cache = Dict{UInt,Vector{Vector{Vector{$T}}}}[]
global const $extra = Dict{UInt,Vector{Dict{UInt,Dict{UInt,$T}}}}[]
end
if field
@eval function Grassmann.$par($(noreg ? :(V::$typ) : :V),a,b,$((noreg ? (:(c::Val{false}),:(d::Val{$field})) : ())...))::$T
$quot
end
@inbounds !haskey($extra[N][S][m1],s) && push!($extra[N][S][m1],s=>Dict{UInt,Dict{UInt,$T}}())
@inbounds !haskey($extra[N][S][m1][s],a) && push!($extra[N][S][m1][s],a=>Dict{UInt,$T}())
@inbounds !haskey($extra[N][S][m1][s][a],b) && push!($extra[N][S][m1][s][a],b=>$calc(M,a,b))
@inbounds $extra[N][S][m1][s][a][b]
elseif n==0
$calc(V,a,b)
else
a1 = a+1
for k length($cache)+1:n
push!($cache,Dict{UInt,Dict{UInt,Vector{Vector{$T}}}}())
end
if !haskey($cache[n],S)
push!($cache[n],S=>Dict{UInt,Vector{Vector{$T}}}[])
end
@inbounds for k length($cache[n][S])+1:m1
@inbounds push!($cache[n][S],Dict{UInt,Vector{Vector{$T}}}())
end
@inbounds !haskey($cache[n][S][m1],s) && push!($cache[n][S][m1],s=>Vector{$T}[])
@inbounds for k length($cache[n][S][m1][s]):a
@inbounds push!($cache[n][S][m1][s],$T[])
end
@inbounds for k length($cache[n][S][m1][s][a1]):b
@inbounds push!($cache[n][S][m1][s][a1],$calc(M,a,k))
@eval @pure function Grassmann.$par($(noreg ? :(V::$typ) : :V),a,b,$((noreg ? (:(c::Val{false}),:(d::Val{$field})) : ())...))::$T
$quot
end
@inbounds $cache[n][S][m1][s][a1][b+1]
end
end
@pure $par(a::Submanifold{V,G,B},b::Submanifold{V,L,C}) where {V,G,B,L,C} = $par(V,UInt(a),UInt(b))
end
end
construct_cache(:Signature)
construct_cache(:DiagonalForm)

@pure signbit(V::T) where T<:Manifold = (ib=indexbasis(rank(V)); parity.(Ref(V),ib,ib))
@pure signbit(V::T,G) where T<:Manifold = (ib=indexbasis(rank(V),G); parity.(Ref(V),ib,ib))
Expand Down

2 comments on commit a6badb9

@chakravala
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/117653

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.8.25 -m "<description of version>" a6badb94aac308d59793511026bce912a6d9617d
git push origin v0.8.25

Please sign in to comment.