Skip to content

Commit

Permalink
transitioned to AbstractTensors v0.1.6 operations
Browse files Browse the repository at this point in the history
  • Loading branch information
chakravala committed Jun 15, 2019
1 parent 784519e commit cacbf40
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 10 deletions.
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"

[compat]
julia = "1"
Reduce = "1.1"
DirectSum = "0.2.3"
AbstractTensors = "0.1.6"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
49 changes: 39 additions & 10 deletions src/algebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# This file is part of Grassmann.jl. It is licensed under the GPL license
# Grassmann Copyright (C) 2019 Michael Reed

import Base: +, -, *, ^, /, inv
import Base: +, -, *, ^, /, inv, <, >, <<, >>, >>>
import AbstractLattices: , , dist
import AbstractTensors:
import AbstractTensors: , , , , , ,
import DirectSum: dualcheck, tangent, hasinforigin, hasorigininf
export tangent

Expand Down Expand Up @@ -100,6 +100,10 @@ end
return out
end

# Hodge star ★

const complementright =

## complement

export complementleft, complementright,
Expand All @@ -117,10 +121,6 @@ for side ∈ (:left,:right)
end
end

# Hodge star ★

const = complementright

## reverse

import Base: reverse, conj, ~
Expand Down Expand Up @@ -177,7 +177,7 @@ end

## exterior product

export ,
export , ,

@pure function (a::Basis{V},b::Basis{V}) where V
A,B = bits(a), bits(b)
Expand All @@ -201,6 +201,10 @@ end
@inline (a::TensorAlgebra{V},b::UniformScaling{T}) where {V,T<:Field} = aV(b)
@inline (a::UniformScaling{T},b::TensorAlgebra{V}) where {V,T<:Field} = V(a)b

for op (:,:^)
@eval $op(a::TensorAlgebra{V},b::TensorAlgebra{V}) where V = ab
end

## regressive product: (L = grade(a) + grade(b); (-1)^(L*(L-ndims(V)))*⋆(⋆(a)∧⋆(b)))

@pure function (a::Basis{V},b::Basis{V}) where V
Expand All @@ -221,6 +225,8 @@ end
@inline (a::TensorAlgebra{V},b::UniformScaling{T}) where {V,T<:Field} = aV(b)
@inline (a::UniformScaling{T},b::TensorAlgebra{V}) where {V,T<:Field} = V(a)b

Base.:&(a::TensorAlgebra{V},b::TensorAlgebra{V}) where V = ab

## interior product: a ∨ ⋆(b)

import LinearAlgebra: dot,
Expand All @@ -240,6 +246,12 @@ function dot(a::X,b::Y) where {X<:TensorTerm{V},Y<:TensorTerm{V}} where V
return SValue{V}(typeof(V) <: Signature ? (g ? -v : v) : g*v,Basis{V}(C))
end

export ,

(a::TensorAlgebra{V},b::TensorAlgebra{V}) where V = (a)b
<(a::TensorAlgebra{V},b::TensorAlgebra{V}) where V = (a)b
>(a::TensorAlgebra{V},b::TensorAlgebra{V}) where V = dot(a,b)

## cross product

import LinearAlgebra: cross
Expand Down Expand Up @@ -277,6 +289,13 @@ function ⊠(x...)
return out/F
end

<<(a::TensorAlgebra{V},b::TensorAlgebra{V}) where V = ab
>>(a::TensorAlgebra{V},b::TensorAlgebra{V}) where V = ab

## sandwich product

>>>(x::TensorAlgebra{V},y::TensorAlgebra{V}) where V = x * y * ~x

### Product Algebra Constructor

function generate_product_algebra(Field=Field,VEC=:mvec,MUL=:*,ADD=:+,SUB=:-,CONJ=:conj)
Expand Down Expand Up @@ -949,12 +968,20 @@ end

@pure inv(b::Basis) = parityreverse(grade(b)) ? -1*b : b
for Value MSV
@eval function inv(b::$Value{V,G,B,T}) where {V,G,B,T}
$Value{V,G,B}((parityreverse(G) ? -one(T) : one(T))/value(b))
@eval begin
function inv(b::$Value{V,G,B,T}) where {V,G,B,T}
$Value{V,G,B}((parityreverse(G) ? -one(T) : one(T))/value(b))
end
rem(b::$Value{V,G,B,T},m) where {V,G,B,T} = $Value{V,G,B}(rem(value(b),m))
div(b::$Value{V,G,B,T},m) where {V,G,B,T} = $Value{V,G,B}(div(value(b),m))
end
end
for Blade MSB
@eval inv(a::$Blade) = (A=~a; A/(Aa))
@eval begin
inv(a::$Blade) = (A=~a; A/(Aa))
rem(a::$Blade{T,V,G},m) where {T,V,G} = $Blade{T,V,G}(rem.(value(a),m))
div(a::$Blade{T,V,G},m) where {T,V,G} = $Blade{T,V,G}(div.(value(a),m))
end
end
for Term (:TensorTerm,MSB...,:MultiVector,:MultiGrade)
@eval begin
Expand All @@ -963,6 +990,8 @@ for Term ∈ (:TensorTerm,MSB...,:MultiVector,:MultiGrade)
@pure /(a::$Term,b::UniformScaling) = a*inv(vectorspace(a)(b))
end
end
rem(a::MultiVector{T,V},m) where {T,V} = MultiVector{T,V}(rem.(value(a),m))
div(a::MultiVector{T,V},m) where {T,V} = MultiVector{T,V}(div.(value(a),m))

## exponential & logarithm function

Expand Down

0 comments on commit cacbf40

Please sign in to comment.