Skip to content

Commit

Permalink
upgraded syntax, fixed error
Browse files Browse the repository at this point in the history
  • Loading branch information
chakravala committed Oct 2, 2024
1 parent 625c0c9 commit 4d9a53d
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 137 deletions.
4 changes: 2 additions & 2 deletions 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.9"
version = "0.8.23"

[deps]
AbstractTensors = "a8e43f4a-99b7-5565-8bf1-0165161caaea"
Expand All @@ -15,7 +15,7 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"

[compat]
julia = "1"
Leibniz = "0.2"
Leibniz = "0.2,0.3"
DirectSum = "0.8.12"
AbstractTensors = "0.8"
ComputedFieldTypes = "1"
Expand Down
70 changes: 4 additions & 66 deletions src/Grassmann.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,20 @@ import Base: @pure, ==, isapprox
import Base: print, show, getindex, setindex!, promote_rule, convert, adjoint
import DirectSum: V0, , generate, basis, getalgebra, getbasis, dual, Zero, One, Zero, One
import Leibniz: hasinf, hasorigin, dyadmode, value, pre, vsn, metric, mdims, gdims
import Leibniz: bit2int, indexbits, indices, diffvars, diffmask
import Leibniz: bit2int, indexbits, indices, diffvars, diffmask, hasconformal
import Leibniz: symmetricmask, indexstring, indexsymbol, combo, digits_fast
import DirectSum: antimetric, signbool
import DirectSum: metrichash, antimetric, signbool

import Leibniz: hasconformal, hasinf2origin, hasorigin2inf
import AbstractTensors: valuetype, scalar, isscalar, trivector, istrivector, , complement
import AbstractTensors: vector, isvector, bivector, isbivector, volume, isvolume
import AbstractTensors: wedgedot_metric, contraction_metric, log_metric

## cache

import Leibniz: algebra_limit, sparse_limit, cache_limit, fill_limit
import Leibniz: algebra_limit, sparse_limit, cache_limit, fill_limit, gdimsall, spincumsum
import Leibniz: binomial, binomial_set, binomsum, binomsum_set, lowerbits, expandbits
import Leibniz: bladeindex, basisindex, indexbasis, indexbasis_set, loworder, intlog
import Leibniz: antisum, antisum_set, antiindex, spinindex
import Leibniz: antisum, antisum_set, anticumsum, antiindex, spinindex, binomcumsum
import Leibniz: promote_type, mvec, svec, intlog, insert_expr, supermanifold

include("multivectors.jl")
Expand Down Expand Up @@ -742,13 +741,6 @@ function __init__()
end
initmesh(t::Chull) = (p=ChainBundle(initpoints(t.points')); Chain{p(list(2,mdims(p))),1}.(t.simplices))
end
@require MiniQhull="978d7f02-9e05-4691-894f-ae31a51d76ca" begin
MiniQhull.delaunay(p::Vector{<:Chain},n=1:length(p)) = MiniQhull.delaunay(ChainBundle(p),n)
function MiniQhull.delaunay(p::ChainBundle,n=1:length(p)); l = list(1,mdims(p))
T = MiniQhull.delaunay(Matrix(submesh(length(n)==length(p) ? p : p[n])'))
[Chain{p,1,Int}(getindex.(Ref(n),Int.(T[l,k]))) for k 1:size(T,2)]
end
end
@require Triangulate = "f7e6ffb2-c36d-4f8f-a77e-16e897189344" begin
const triangle_cache = (Array{T,2} where T)[]
function triangle(p::Array{T,2} where T,B)
Expand Down Expand Up @@ -814,60 +806,6 @@ function __init__()
initmesh(TetGen.JLTetGenIO(mesh;marker=marker,holes=holes),command)
end
end
@require MATLAB="10e44e05-a98a-55b3-a45b-ba969058deb6" begin
const matlab_cache = (Array{T,2} where T)[]
function matlab(p::Array{T,2} where T,B)
for k length(matlab_cache):B
push!(matlab_cache,Array{Any,2}(undef,0,0))
end
matlab_cache[B] = p
end
function matlab(p::ChainBundle{V,G,T,B} where {V,G,T}) where B
if length(matlab_cache)<B || isempty(matlab_cache[B])
ap = array(p)'
matlab(islocal(p) ? vcat(ap,ones(length(p))') : ap[2:end,:],B)
else
return matlab_cache[B]
end
end
initmesh(g,args...) = initmeshall(g,args...)[1:3]
initmeshall(g::Matrix{Int},args...) = initmeshall(Matrix{Float64}(g),args...)
function initmeshall(g,args...)
P,E,T = MATLAB.mxcall(:initmesh,3,g,args...)
p,e,t = initmeshdata(P,E,T,Val(2))
return (p,e,t,T,E,P)
end
function initmeshes(g,args...)
p,e,t,T = initmeshall(g,args...)
p,e,t,[Int(T[end,k]) for k 1:size(T,2)]
end
export initmeshes
function refinemesh(g,args...)
p,e,t,T,E,P = initmeshall(g,args...)
matlab(P,bundle(p)); matlab(E,bundle(e)); matlab(T,bundle(t))
return (g,p,e,t)
end
refinemesh3(g,p::ChainBundle,e,t,s...) = MATLAB.mxcall(:refinemesh,3,g,matlab(p),matlab(e),matlab(t),s...)
refinemesh4(g,p::ChainBundle,e,t,s...) = MATLAB.mxcall(:refinemesh,4,g,matlab(p),matlab(e),matlab(t),s...)
refinemesh(g,p::ChainBundle,e,t) = refinemesh3(g,p,e,t)
refinemesh(g,p::ChainBundle,e,t,s::String) = refinemesh3(g,p,e,t,s)
refinemesh(g,p::ChainBundle,e,t,η::Vector{Int}) = refinemesh3(g,p,e,t,float.(η))
refinemesh(g,p::ChainBundle,e,t,η::Vector{Int},s::String) = refinemesh3(g,p,e,t,float.(η),s)
refinemes(g,p::ChainBundle,e,t,u) = refinemesh4(g,p,e,t,u)
refinemesh(g,p::ChainBundle,e,t,u,s::String) = refinemesh4(g,p,e,t,u,s)
refinemesh(g,p::ChainBundle,e,t,u,η) = refinemesh4(g,p,e,t,u,float.(η))
refinemesh(g,p::ChainBundle,e,t,u,η,s) = refinemesh4(g,p,e,t,u,float.(η),s)
refinemesh!(g::Matrix{Int},p::ChainBundle,args...) = refinemesh!(Matrix{Float64}(g),p,args...)
function refinemesh!(g,p::ChainBundle{V},e,t,s...) where V
P,E,T = refinemesh(g,p,e,t,s...); l = size(P,1)+1
matlab(P,bundle(p)); matlab(E,bundle(e)); matlab(T,bundle(t))
submesh!(p); array!(t); el,tl = list(1,l-1),list(1,l)
bundle_cache[bundle(p)] = [Chain{V,1,Float64}(vcat(1,P[:,k])) for k 1:size(P,2)]
bundle_cache[bundle(e)] = [Chain{↓(p),1,Int}(Int.(E[el,k])) for k 1:size(E,2)]
bundle_cache[bundle(t)] = [Chain{p,1,Int}(Int.(T[tl,k])) for k 1:size(T,2)]
return (p,e,t)
end
end
end

# ____ ____ ____ _____ _____ ___ ___ ____ ____ ____
Expand Down
2 changes: 1 addition & 1 deletion src/algebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import Base: +, -, *, ^, /, //, inv, <, >, <<, >>, >>>
import AbstractTensors: , , , , , , , , , , , rem, div, TAG, SUB
import AbstractTensors: plus, minus, times, contraction, equal, wedgedot, veedot
import AbstractTensors: pseudosandwich, antisandwich, antidot
import Leibniz: diffcheck, diffmode, hasinforigin, hasorigininf, symmetricsplit
import Leibniz: diffcheck, diffmode, symmetricsplit
import Leibniz: loworder, isnull, Field, ExprField
const Sym,SymField = :AbstractTensors,Any

Expand Down
4 changes: 2 additions & 2 deletions src/forms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ end
function (a::Chain{V,1})(b::Single{V,1}) where V
(!isdyadic(V)) && (return contraction(a,b))
$(insert_expr((:t,))...)
x = bits(b)
x = UInt(b)
X = isdyadic(V) ? x<<Int(mdims(V)/2) : x
Y = X>2^mdims(V) ? x : X
@inbounds out = a.v[bladeindex(mdims(V),Y)]
Expand Down Expand Up @@ -871,7 +871,7 @@ gradedoperator(fun,V) = TensorOperator(Multivector{V}(fun.(Λ(V).b)))
@pure evendyad(V) = Spinor.(evenbasis(V))
@pure function evenbasis(V,even=true)
N = mdims(V)
r,b = binomsum_set(N),binomial_set(N)
r,b = binomsum_set(N),gdimsall(N)
vcat([Λ(V).b[list(r[g]+1,r[g]+b[g])] for g evens(even ? 1 : 2,N+1)]...)
end
evenoperator(t::TensorAlgebra{V}) where V = TensorOperator(Spinor{V}(evenbasis(V) .⊘ Ref(t)))
Expand Down
40 changes: 6 additions & 34 deletions src/parity.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,48 +34,20 @@ export involute, clifford, pseudoreverse, antireverse
isodd(sum(digits_fast(a,N) .* cumsum(digits_fast(b<<1,N)))+count_ones((a & b) & S))
end

@pure conformalmask(V) = UInt(2)^(hasinf(V)&&hasorigin(V) ? 2 : 0)-1

@pure function conformalcheck(V,A,B)
bt = conformalmask(V)
i2o,o2i = hasinf2origin(V,A,B),hasorigin2inf(V,A,B)
A&bt, B&bt, i2o, o2i, i2o o2i
end

@pure function parityconformal(V,A,B)
C,cc = A B, hasinforigin(V,A,B) || hasorigininf(V,A,B)
A3,B3,i2o,o2i,xor = conformalcheck(V,A,B)
pcc,bas = xori2o(i2o&o2i), xor ? (A3|B3)C : C
return pcc, bas, cc, Zero(UInt)
end

function paritycomplementinverse(N,G)#,S)
parityreverse(N-G)parityreverse(G)isodd(binomial(N,2))#⊻isodd(count_ones(S))
end

function cga(V,A,B)
(hasinforigin(V,A,B) || hasorigininf(V,A,B)) && iszero(getbasis(V,A)∨⋆(getbasis(V,B)))
end

@pure parityregressive(V::Int,a,b,skew=Val(false)) = _parityregressive(V,a,b,skew)
@pure function _parityregressive(V,a,b,::Val{skew}=Val(false)) where skew
N,M,S = mdims(V),options(V),metric(V)
D,G = diffvars(V),typeof(V)<:Int ? V : grade(V)
N,S,D,G = mdims(V),metric(V),diffvars(V),typeof(V)<:Int ? V : grade(V)
A,B,Q,Z = symmetricmask(V,a,b)
α,β = complement(N,A,D),complement(N,B,D)
cc = skew && (hasinforigin(V,A,β) || hasorigininf(V,A,β))
if ((count_ones&β)==0) && !diffcheck(V,α,β)) #|| cc
if ((count_ones&β)==0) && !diffcheck(V,α,β))
C,L = α β, count_ones(A)+count_ones(B)
bas = complement(N,C,D)
pcc,bas = if skew
A3,β3,i2o,o2i,xor = UInt(0),UInt(0),false,false,false#conformalcheck(V,A,β)
cx = cc || xor
cx && parity(V,A3,β3)(i2o || o2i)(xor&!i2o), cx ? (A3|β3)bas : bas
else
false, A+B0 ? bas : Zero(UInt)
end
bas = skew || A+B0 ? complement(N,C,D) : Zero(UInt)
par = parityright(S,A,N)parityright(S,B,N)parityright(S,C,N)
return (isodd(L*(L-G))parparity(N,S,α,β)pcc)::Bool, bas|Q, true, Z
return (isodd(L*(L-G))parparity(N,S,α,β))::Bool, bas|Q, true, Z
else
return false, Zero(UInt), false, Z
end
Expand All @@ -89,7 +61,7 @@ end

@pure function parityinterior(V::Int,a,b)
A,B,Q,Z = symmetricmask(V,a,b)
(diffcheck(V,A,B) || cga(V,A,B)) && (return false,Zero(UInt),false,Z)
diffcheck(V,A,B) && (return false,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
Expand Down Expand Up @@ -131,7 +103,7 @@ end
end
bs,bg = (),()
for i list(1,diag ? 1 : gdims(grade(V),G))
if (!isnull(g[i])) && !(diffcheck2(V,A,bas[i]) || cga(V,A,bas[i]))
if (!isnull(g[i])) && !diffcheck2(V,A,bas[i])
p,C,t = parityregressive(Signature(W),A,complement(N,bas[i],diffvars(V)),Val{true}())
CQ,tout = C|Q,tout|t
if t
Expand Down
50 changes: 18 additions & 32 deletions src/products.jl
Original file line number Diff line number Diff line change
Expand Up @@ -211,51 +211,37 @@ function generate_mutators(M,F,set_val,SUB,MUL)
@inline function $(Symbol(:geom,s))(V,m::$M,a::UInt,b::UInt,v::S) where {T<:$F,S<:$F,M}
if v 0 && !diffcheck(V,a,b)
A,B,Q,Z = symmetricmask(V,a,b)
if isdiag(V)
pcc,bas,cc = (hasinf(V) && hasorigin(V)) ? conformal(V,A,B) : (false,AB,false)
g = parityinner(V,A,B)
val = $MUL(g,pcc ? $SUB(v) : v)
basg = if isdiag(V)
Values(((AB,parityinner(V,A,B)),))
else
paritygeometric(V,A,B)
end
for (bas,g) basg
val = $MUL(g,v)
if istangent(V)
!iszero(Z) && (TAny ? (return true) : (val *= getbasis(loworder(V),Z)))
count_ones(Q)+order(val)>diffmode(V) && (return false)
end
$s(m,val,bas|Q,Val(mdims(V)))
cc && $s(m,hasinforigin(V,A,B) ? $SUB(val) : val,(conformalmask(V)bas)|Q,Val(mdims(V)))
else
for (bas,g) paritygeometric(V,A,B)
val = $MUL(g,v)
if istangent(V)
!iszero(Z) && (TAny ? (return true) : (val *= getbasis(loworder(V),Z)))
count_ones(Q)+order(val)>diffmode(V) && (return false)
end
$s(m,val,bas|Q,Val(mdims(V)))
end
end
end
return false
end
@inline function $(Symbol(:geom,spre))(V,m::$M,a::UInt,b::UInt,v::S,vfield::Val{field}=Val(false)) where {T<:$F,S<:$F,M,field}
if v 0 && !diffcheck(V,a,b)
A,B,Q,Z = symmetricmask(V,a,b)
if isdiag(V)
pcc,bas,cc = (hasinf(V) && hasorigin(V)) ? conformal(V,A,B) : (false,AB,false)
g = parityinner(V,A,B,vfield)
val = :($$MUL($g,$(pcc ? :($$SUB($v)) : v)))
basg = if isdiag(V)
Values(((AB,parityinner(V,A,B,vfield)),))
else
paritygeometric(V,A,B,vfield)
end
for (bas,g) basg
val = :($$MUL($g,$v))
if istangent(V)
!iszero(Z) && (val = Expr(:call,:*,val,getbasis(loworder(V),Z)))
val = :(h=$val;iszero(h)||$(count_ones(Q))+order(h)>$(diffmode(V)) ? 0 : h)
end
$spre(m,val,bas|Q,Val(mdims(V)))
cc && $spre(m,hasinforigin(V,A,B) ? :($$SUB($val)) : val,(conformalmask(V)bas)|Q,Val(mdims(V)))
else
for (bas,g) paritygeometric(V,A,B,vfield)
val = :($$MUL($g,$v))
if istangent(V)
!iszero(Z) && (val = Expr(:call,:*,val,getbasis(loworder(V),Z)))
val = :(h=$val;iszero(h)||$(count_ones(Q))+order(h)>$(diffmode(V)) ? 0 : h)
end
$spre(m,val,bas|Q,Val(mdims(V)))
end
end
end
return false
Expand Down Expand Up @@ -363,10 +349,10 @@ end
@inline exteraddblade!(V,out,α,β,γ) = exterbits(V,α,β) && joinaddblade!(V,out,α,β,γ)
@inline exteraddspin!(V,out,α,β,γ) = exterbits(V,α,β) && joinaddspin!(V,out,α,β,γ)
@inline exteraddanti!(V,out,α,β,γ) = exterbits(V,α,β) && joinaddanti!(V,out,α,β,γ)
@inline exteraddmulti!_pre(V,out,α,β,γ) = exterbits(V,α,β) && joinaddmulti!_pre(V,out,α,β,γ)
@inline exteraddblade!_pre(V,out,α,β,γ) = exterbits(V,α,β) && joinaddblade!_pre(V,out,α,β,γ)
@inline exteraddspin!_pre(V,out,α,β,γ) = exterbits(V,α,β) && joinaddspin!_pre(V,out,α,β,γ)
@inline exteraddanti!_pre(V,out,α,β,γ) = exterbits(V,α,β) && joinaddanti!_pre(V,out,α,β,γ)
@inline exteraddmulti!_pre(V,out,α,β,γ,f=Val(false)) = exterbits(V,α,β) && joinaddmulti!_pre(V,out,α,β,γ,f)
@inline exteraddblade!_pre(V,out,α,β,γ,f=Val(false)) = exterbits(V,α,β) && joinaddblade!_pre(V,out,α,β,γ,f)
@inline exteraddspin!_pre(V,out,α,β,γ,f=Val(false)) = exterbits(V,α,β) && joinaddspin!_pre(V,out,α,β,γ,f)
@inline exteraddanti!_pre(V,out,α,β,γ,f=Val(false)) = exterbits(V,α,β) && joinaddanti!_pre(V,out,α,β,γ,f)

# algebra

Expand Down

2 comments on commit 4d9a53d

@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/116470

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.23 -m "<description of version>" 4d9a53db19c2e91f23570fae74e43a59b51c3b4b
git push origin v0.8.23

Please sign in to comment.