Skip to content

Commit

Permalink
generated Leibniz algebra, improved dispatch, fixed #22
Browse files Browse the repository at this point in the history
  • Loading branch information
chakravala committed Jun 10, 2019
1 parent 71f7322 commit 0c68892
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/Grassmann.jl
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,9 @@ end
# ParaAlgebra

function __init__()
@require Leibniz="edad4870-8a01-11e9-2d75-8f02e448fc59" generate_product_algebra(:(Leibniz.Operator),:svec)
@require Reduce="93e0c654-6965-5f22-aba9-9c1ae6b3c259" include("symbolic.jl")
@require SymPy="24249f21-da20-56a4-8eb1-6a02cf4ae2e6" generate_product_algebra(:(SymPy.Sym),:(SymPy.:*),:(SymPy.:+),:(SymPy.:-),:svec,:(SymPy.conj))
@require SymPy="24249f21-da20-56a4-8eb1-6a02cf4ae2e6" generate_product_algebra(:(SymPy.Sym),:svec,:(SymPy.:*),:(SymPy.:+),:(SymPy.:-),:(SymPy.conj))
end

end # module
10 changes: 5 additions & 5 deletions src/algebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function declare_mutating_operations(M,F,set_val,SUB,MUL)
pcc,bas,cc = (hasinf(V) && hasorigin(V)) ? conformal(A,B,V) : (false,AB,false)
val = (typeof(V)<:Signature || count_ones(A&B)==0) ? (parity(A,B,V)pcc ? $SUB(v) : v) : $MUL(parityinner(A,B,V),pcc ? $SUB(v) : v)
$s(m,val,bas,Dimension{N}())
cc && $s(m,DirectSum.hasinforigin(V,A,B) ? $SUB(val) : val,conformalmask(V)bas,Dimension{N}())
cc && $s(m,hasinforigin(V,A,B) ? $SUB(val) : val,conformalmask(V)bas,Dimension{N}())
end
return m
end
Expand Down Expand Up @@ -269,7 +269,7 @@ export ⨲

### Product Algebra Constructor

function generate_product_algebra(Field=Field,MUL=:*,ADD=:+,SUB=:-,VEC=:mvec,CONJ=:conj)
function generate_product_algebra(Field=Field,VEC=:mvec,MUL=:*,ADD=:+,SUB=:-,CONJ=:conj)
if Field == Grassmann.Field
declare_mutating_operations(:(MArray{Tuple{M},T,1,M}),Field,Expr,:-,:*)
elseif Field (SymField,:(SymPy.Sym))
Expand Down Expand Up @@ -305,8 +305,8 @@ function generate_product_algebra(Field=Field,MUL=:*,ADD=:+,SUB=:-,VEC=:mvec,CON
end
*(a::F,b::Basis{V}) where {F<:$EF,V} = SValue{V}(a,b)
*(a::Basis{V},b::F) where {F<:$EF,V} = SValue{V}(b,a)
*(a::F,b::MultiVector{T,V}) where {F<:$EF,T<:$EF,V} = MultiVector{promote_type(T,F),V}(broadcast($MUL,a,b.v))
*(a::MultiVector{T,V},b::F) where {F<:$EF,T<:$EF,V} = MultiVector{promote_type(T,F),V}(broadcast($MUL,a.v,b))
*(a::F,b::MultiVector{T,V}) where {F<:$Field,T<:$Field,V} = MultiVector{promote_type(T,F),V}(broadcast($MUL,a,b.v))
*(a::MultiVector{T,V},b::F) where {F<:$Field,T<:$Field,V} = MultiVector{promote_type(T,F),V}(broadcast($MUL,a.v,b))
*(a::F,b::MultiGrade{V}) where {F<:$EF,V} = MultiGrade{V}(broadcast($MUL,a,b.v))
*(a::MultiGrade{V},b::F) where {F<:$EF,V} = MultiGrade{V}(broadcast($MUL,a.v,b))
(a::$Field,b::$Field) = $MUL(a,b)
Expand Down Expand Up @@ -878,7 +878,7 @@ function generate_product_algebra(Field=Field,MUL=:*,ADD=:+,SUB=:-,VEC=:mvec,CON
end

generate_product_algebra()
generate_product_algebra(SymField,:($Sym.:*),:($Sym.:+),:($Sym.:-),:svec,:($Sym.conj))
generate_product_algebra(SymField,:svec,:($Sym.:*),:($Sym.:+),:($Sym.:-),:($Sym.conj))

const NSE = Union{Symbol,Expr,<:Number}

Expand Down
5 changes: 3 additions & 2 deletions src/multivectors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ for (Blade,vector,Value) ∈ ((MSB[1],:MVector,MSV[1]),(MSB[2],:SVector,MSV[2]))
end

function $Blade{T,V,G}(val::T,v::Basis{V,G}) where {T,V,G}
SBlade{T,V}(setblade!(zeros(mvec(ndims(V),G,T)),val,bits(v),Dimension{N}()))
N = ndims(V)
SBlade{T,V}(setblade!(zeros(mvec(N,G,T)),val,bits(v),Dimension{N}()))
end

$Blade(v::Basis{V,G}) where {V,G} = $Blade{Int,V,G}(one(Int),v)
Expand Down Expand Up @@ -258,7 +259,7 @@ for var ∈ ((:T,:V),(:T,),())
N = ndims(V)
out = zeros(mvec(N,T))
r = binomsum(N,G)
@inbounds out.v[r+1:r+binomial(N,G)] = v.v
@inbounds out[r+1:r+binomial(N,G)] = v.v
return MultiVector{T,V}(out)
end
end
Expand Down

0 comments on commit 0c68892

Please sign in to comment.