Skip to content

Commit

Permalink
transitioned ∧ ∨ clifford conj and rand samplers #59
Browse files Browse the repository at this point in the history
  • Loading branch information
chakravala committed Apr 28, 2020
1 parent c2aa2e6 commit 7bbc28e
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 13 deletions.
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 5 additions & 3 deletions src/algebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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))/(yy)


@doc """
Expand Down
10 changes: 10 additions & 0 deletions src/composite.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
6 changes: 3 additions & 3 deletions src/parity.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -12,7 +12,7 @@ export complementleft, complementright, ⋆, complementlefthodge, complementrigh
## reverse

import Base: reverse, conj, ~
export involute
export involute, clifford

## product parities

Expand Down
12 changes: 6 additions & 6 deletions src/products.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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 ? Ww : wW) : (return :(interop(,a,b))))
V = w==W ? w : ((w==dual(W)) ? (dyadmode(w)0 ? Ww : wW) : (return :(interop($$op,a,b))))
$po(G+L,ndims(V)) && (!istangent(V)) && (return g_zero(V))
if binomial(ndims(w),G)<(1<<cache_limit)
$(insert_expr((:N,:t,),VEC,:T,Int)...)
Expand Down Expand Up @@ -435,7 +435,7 @@ function generate_products(Field=Field,VEC=:mvec,MUL=:*,ADD=:+,SUB=:-,CONJ=:conj
end end
end
@generated function $op(a::SubManifold{w,G},b::Chain{W,L,T}) where {w,W,T<:$Field,G,L}
V = w==W ? w : ((w==dual(W)) ? (dyadmode(w)0 ? Ww : wW) : (return :(interop(,a,b))))
V = w==W ? w : ((w==dual(W)) ? (dyadmode(w)0 ? Ww : wW) : (return :(interop($$op,a,b))))
$po(G+L,ndims(V)) && (!istangent(V)) && (return g_zero(V))
if binomial(ndims(W),L)<(1<<cache_limit)
$(insert_expr((:N,:t,),VEC,Int,:T)...)
Expand Down Expand Up @@ -516,7 +516,7 @@ function generate_products(Field=Field,VEC=:mvec,MUL=:*,ADD=:+,SUB=:-,CONJ=:conj
end end
end
@generated function $op(a::Simplex{w,G,B,S},b::Chain{W,L,T}) where {T<:$Field,w,W,B,S<:$Field,G,L}
V = w==W ? w : ((w==dual(W)) ? (dyadmode(w)0 ? Ww : wW) : (return :(interop(,a,b))))
V = w==W ? w : ((w==dual(W)) ? (dyadmode(w)0 ? Ww : wW) : (return :(interop($$op,a,b))))
$po(G+L,ndims(V)) && (!istangent(V)) && (return g_zero(V))
if binomial(ndims(W),L)<(1<<cache_limit)
$(insert_expr((:N,:t,),VEC,:S,:T)...)
Expand Down Expand Up @@ -556,7 +556,7 @@ function generate_products(Field=Field,VEC=:mvec,MUL=:*,ADD=:+,SUB=:-,CONJ=:conj
end end
end
@generated function $op(a::Chain{w,G,T},b::Chain{W,L,S}) where {T<:$Field,w,S<:$Field,W,G,L}
V = w==W ? w : ((w==dual(W)) ? (dyadmode(w)0 ? Ww : wW) : (return :(interop(,a,b))))
V = w==W ? w : ((w==dual(W)) ? (dyadmode(w)0 ? Ww : wW) : (return :(interop($$op,a,b))))
$po(G+L,ndims(V)) && (!istangent(V)) && (return g_zero(V))
if binomial(ndims(w),G)*binomial(ndims(W),L)<(1<<cache_limit)
$(insert_expr((:N,:t,),VEC,:T,:S)...)
Expand Down Expand Up @@ -856,7 +856,7 @@ function generate_products(Field=Field,VEC=:mvec,MUL=:*,ADD=:+,SUB=:-,CONJ=:conj
end
end
end
for reverse (:reverse,:involute,:conj)
for reverse (:reverse,:involute,:conj,:clifford)
p = Symbol(:parity,reverse)
@eval begin
@generated function $reverse(b::Chain{V,G,T}) where {V,G,T<:$Field}
Expand Down

2 comments on commit 7bbc28e

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

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.5.9 -m "<description of version>" 7bbc28e0b6d28018dca8d91b07e131341825eac4
git push origin v0.5.9

Please sign in to comment.