From 7bbc28e0b6d28018dca8d91b07e131341825eac4 Mon Sep 17 00:00:00 2001 From: Michael Reed <18372368+chakravala@users.noreply.github.com> Date: Tue, 28 Apr 2020 03:26:05 -0400 Subject: [PATCH] =?UTF-8?q?transitioned=20=E2=88=A7=20=E2=88=A8=20clifford?= =?UTF-8?q?=20conj=20and=20rand=20samplers=20#59?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Project.toml | 3 ++- src/algebra.jl | 8 +++++--- src/composite.jl | 10 ++++++++++ src/parity.jl | 6 +++--- src/products.jl | 12 ++++++------ 5 files changed, 26 insertions(+), 13 deletions(-) diff --git a/Project.toml b/Project.toml index 76e581f..1cded7e 100644 --- a/Project.toml +++ b/Project.toml @@ -12,11 +12,12 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" Requires = "ae029012-a4dd-5104-9daa-d747884805df" StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" +Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" [compat] julia = "1" Leibniz = "0.0.5" -DirectSum = "0.5.3" +DirectSum = "0.5.7" AbstractTensors = "0.4.3" ComputedFieldTypes = "0.1" StaticArrays = "0" diff --git a/src/algebra.jl b/src/algebra.jl index 435f8a8..3ae4c7c 100644 --- a/src/algebra.jl +++ b/src/algebra.jl @@ -392,7 +392,7 @@ end function ∨(a::X,b::Y) where {X<:TensorTerm{V},Y<:TensorTerm{V}} where V ba,bb = bits(basis(a)),bits(basis(b)) - p,C,t,Z = regressive(ba,bb,V) + p,C,t,Z = regressive(V,ba,bb) !t && (return g_zero(V)) v = derive_mul(V,ba,bb,value(a),value(b),AbstractTensors.∏) if istangent(V) && !iszero(Z) @@ -529,9 +529,11 @@ Anti-symmetrization projection: ⊠(ω...) = ∑(∏(πσ.(ω)...))/factorial(le export ⊘ for X ∈ TAG, Y ∈ TAG - @eval ⊘(x::$X{V},y::$Y{V}) where V = diffvars(V)≠0 ? conj(y)*x*y : y\x*involute(y) + @eval ⊘(x::X,y::Y) where {X<:$X{V},Y<:$Y{V}} where V = diffvars(V)≠0 ? conj(y)*x*y : y\x*involute(y) +end +for Z ∈ TAG + @eval ⊘(x::Chain{V,G},y::T) where {V,G,T<:$Z} = diffvars(V)≠0 ? conj(y)*x*y : ((~y)*x*involute(y))(Val(G))/abs2(y) end -⊘(x::Chain{V,1},y::T) where {V,G,T<:TensorAlgebra} = diffvars(V)≠0 ? conj(y)*x*y : ((~y)*x*involute(y))(Val(G))/(y⊛y) @doc """ diff --git a/src/composite.jl b/src/composite.jl index 16d517c..1a56b34 100644 --- a/src/composite.jl +++ b/src/composite.jl @@ -452,3 +452,13 @@ end Base.map(fn, x::MultiVector{V}) where V = MultiVector{V}(map(fn, value(x))) Base.map(fn, x::Chain{V,G}) where {V,G} = Chain{V,G}(map(fn,value(x))) Base.map(fn, x::Simplex{V,G,B}) where {V,G,B} = fn(value(x))*B + +import Random: SamplerType, AbstractRNG +Base.rand(::AbstractRNG,::SamplerType{Chain}) = rand(Chain{rand(Manifold)}) +Base.rand(::AbstractRNG,::SamplerType{Chain{V}}) where V = rand(Chain{V,rand(0:ndims(V))}) +Base.rand(::AbstractRNG,::SamplerType{Chain{V,G}}) where {V,G} = Chain{V,G}(DirectSum.orand(svec(ndims(V),G,Float64))) +Base.rand(::AbstractRNG,::SamplerType{Chain{V,G,T}}) where {V,G,T} = Chain{V,G}(rand(svec(ndims(V),G,T))) +Base.rand(::AbstractRNG,::SamplerType{Chain{V,G,T} where G}) where {V,T} = rand(Chain{V,rand(0:ndims(V)),Float64}) +Base.rand(::AbstractRNG,::SamplerType{MultiVector}) = rand(MultiVector{rand(Manifold)}) +Base.rand(::AbstractRNG,::SamplerType{MultiVector{V}}) where V = MultiVector{V}(DirectSum.orand(svec(ndims(V),Float64))) +Base.rand(::AbstractRNG,::SamplerType{MultiVector{V,T}}) where {V,T} = MultiVector{V}(rand(svec(ndims(V),T))) diff --git a/src/parity.jl b/src/parity.jl index 7decf88..0a8a624 100644 --- a/src/parity.jl +++ b/src/parity.jl @@ -2,8 +2,8 @@ # This file is part of Grassmann.jl. It is licensed under the AGPL license # Grassmann Copyright (C) 2019 Michael Reed -import DirectSum: parityreverse, parityinvolute, parityconj, parityright, parityleft, parityrighthodge, paritylefthodge, involute, grade_basis, odd, even -import DirectSum: complementleft, complementright, ⋆, complementlefthodge, complementrighthodge, complement +import DirectSum: parityreverse, parityinvolute, parityconj, parityclifford, parityright, parityleft, parityrighthodge, paritylefthodge, odd, even, involute, clifford +import DirectSum: complementleft, complementright, ⋆, complementlefthodge, complementrighthodge, complement, grade_basis ## complement @@ -12,7 +12,7 @@ export complementleft, complementright, ⋆, complementlefthodge, complementrigh ## reverse import Base: reverse, conj, ~ -export involute +export involute, clifford ## product parities diff --git a/src/products.jl b/src/products.jl index 6699725..d3d836b 100644 --- a/src/products.jl +++ b/src/products.jl @@ -387,14 +387,14 @@ function generate_products(Field=Field,VEC=:mvec,MUL=:*,ADD=:+,SUB=:-,CONJ=:conj ∧(a::$Field,b::MultiGrade{V,G}) where V = MultiGrade{V,G}(a.*b.v) ∧(a::MultiGrade{V,G},b::$Field) where V = MultiGrade{V,G}(a.v.*b)=# end - for (op,po,GL,grass) ∈ ((:∧,:>,:(G+L),:exter),(:∨,:<,:(abs(G-L)),:meet)) + for (op,po,GL,grass) ∈ ((:∧,:>,:(G+L),:exter),(:∨,:<,:(G+L-ndims(V)),:meet)) grassaddmulti! = Symbol(grass,:addmulti!) grassaddblade! = Symbol(grass,:addblade!) grassaddmulti!_pre = Symbol(grassaddmulti!,:_pre) grassaddblade!_pre = Symbol(grassaddblade!,:_pre) @eval begin @generated function $op(a::Chain{w,G,T},b::SubManifold{W,L}) where {w,G,T<:$Field,W,L} - V = w==W ? w : ((w==dual(W)) ? (dyadmode(w)≠0 ? W⊕w : w⊕W) : (return :(interop(∧,a,b)))) + V = w==W ? w : ((w==dual(W)) ? (dyadmode(w)≠0 ? W⊕w : w⊕W) : (return :(interop($$op,a,b)))) $po(G+L,ndims(V)) && (!istangent(V)) && (return g_zero(V)) if binomial(ndims(w),G)<(1<