Skip to content

Commit

Permalink
transitioned DirectSum algebra dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
chakravala committed Sep 5, 2019
1 parent dceed14 commit 6c3a635
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 24 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ os:
julia:
- 1.0
- 1.1
- 1.2
- nightly
matrix:
allow_failures:
Expand Down
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Leibniz"
uuid = "edad4870-8a01-11e9-2d75-8f02e448fc59"
authors = ["Michael Reed"]
version = "0.0.2"
version = "0.0.3"

[deps]
AbstractTensors = "a8e43f4a-99b7-5565-8bf1-0165161caaea"
Expand All @@ -12,7 +12,7 @@ StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"

[compat]
julia = "1"
DirectSum = "0.3"
DirectSum = ">= 0.3"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
1 change: 1 addition & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ environment:
matrix:
- julia_version: 1
- julia_version: 1.1
- julia_version: 1.2
- julia_version: nightly

platform:
Expand Down
37 changes: 30 additions & 7 deletions src/Leibniz.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Leibniz
using DirectSum, StaticArrays #, Requires
using LinearAlgebra, AbstractTensors, AbstractLattices
import Base: *, ^, +, -, /, show, zero
import DirectSum: value, V0, mixedmode, pre
import DirectSum: value, V0, mixedmode, pre, diffmode

export Differential, Monomial, Derivation, d, ∂, ∇, Δ, @operator

Expand Down Expand Up @@ -56,17 +56,40 @@ indexint(D) = DirectSum.bit2int(DirectSum.indexbits(max(D...),D))
*(d::Monomial{V,G,D,0} where {V,G,D},r) = r
*(d::Monomial{V,G,0,O} where {V,G,O},r) = r
*(d::Monomial{V,0,D,O} where {V,D,O},r) = r
*(a::Monomial{V,1,D,O1},b::Monomial{V,1,D,O2}) where {V,D,O1,O2} = (c=a.v*b.v; iszero(c) ? 0 : Monomial{V,2,D,O1+O2}(c))
*(a::Monomial{V,1,D,1},b::Monomial{V,1,D,1}) where {V,D,O1,O2} = (c=a.v*b.v; iszero(c) ? 0 : Monomial{V,2,D,2}(c))
*(a::Monomial{V,1,D1,1},b::Monomial{V,1,D2,1}) where {V,D1,D2} = (c=a.v*b.v; iszero(c) ? 0 : Monomial{V,2,D1|D2}(c))
function *(a::Monomial{V,1,D,O1},b::Monomial{V,1,D,O2}) where {V,D,O1,O2}
O = O1+O2
O > diffmode(V) && (return 0)
c = a.v*b.v
iszero(c) ? 0 : Monomial{V,2,D,O1+O2}(c)
end
function *(a::Monomial{V,1,D,1},b::Monomial{V,1,D,1}) where {V,D,O1,O2}
2 > diffmode(V) && (return 0)
c = a.v*b.v
iszero(c) ? 0 : Monomial{V,2,D,2}(c)
end
function *(a::Monomial{V,1,D1,1},b::Monomial{V,1,D2,1}) where {V,D1,D2}
2 > diffmode(V) && (return 0)
c = a.v*b.v
iszero(c) ? 0 : Monomial{V,2,D1|D2}(c)
end
*(a::Monomial{V,G,D,O,Bool},b::I) where {V,G,D,O,I<:Number} = isone(b) ? a : Monomial{V,G,D,O,I}(value(a) ? b : -b)
*(a::Monomial{V,G,D,O,T},b::I) where {V,G,D,O,T,I<:Number} = isone(b) ? a : Monomial{V,G,D,O}(value(a)*b)
+(a::Monomial{V,G,D,O},b::Monomial{V,G,D,O}) where {V,G,D,O} = (c=a.v+b.v; iszero(c) ? 0 : Monomial{V,G,D,O}(c))
-(a::Monomial{V,G,D,O},b::Monomial{V,G,D,O}) where {V,G,D,O} = (c=a.v-b.v; iszero(c) ? 0 : Monomial{V,G,D,O}(c))
#-(d::Monomial{V,G,D,O,Bool}) where {V,G,D,O} = Monomial{V,G,D,O,Bool}(!value(d))
-(d::Monomial{V,G,D,O}) where {V,G,D,O} = Monomial{V,G,D,O}(-value(d))
^(d::Monomial{V,G,D,O},o::T) where {V,G,D,O,T<:Integer} = iszero(o) ? 1 : Monomial{V,G+(O*o),D,O*o}(value(d)^o)
^(d::Monomial{V,G,D,O,Bool},o::T) where {V,G,D,O,T<:Integer} = iszero(o) ? 1 : Monomial{V,G+(O*o),D,O*o}(value(d) ? true : iseven(o))
function ^(d::Monomial{V,G,D,O},o::T) where {V,G,D,O,T<:Integer}
Oo = O*o
GOo = G+Oo
GOo > diffmode(V) && (return 0)
iszero(o) ? 1 : Monomial{V,GOo,D,Oo}(value(d)^o)
end
function ^(d::Monomial{V,G,D,O,Bool},o::T) where {V,G,D,O,T<:Integer}
Oo = O*o
GOo = G+Oo
GOo > diffmode(V) && (return 0)
iszero(o) ? 1 : Monomial{V,GOo,D,Oo}(value(d) ? true : iseven(o))
end

struct OperatorExpr{T} <: Operator{T}
expr::T
Expand Down Expand Up @@ -131,6 +154,7 @@ end

*(d::OperatorExpr,n::Monomial) = times(d,n)
*(d::OperatorExpr,n::OperatorExpr) = OperatorExpr(Expr(:call,:*,d,n))
*(n::T,d::OperatorExpr) where T<:Number = OperatorExpr(DirectSum.(n,d.expr))

*(a::Monomial{V,1},b::Monomial{V,1,D,O}) where {V,D,O} = Monomial{V,1,D,O}(a*OperatorExpr(b.v))
*(a::Monomial,b::Monomial{V,G,D,O}) where {V,G,D,O} = Monomial{V,G,D,O}(a*OperatorExpr(b.v))
Expand Down Expand Up @@ -192,7 +216,6 @@ const Δ = ∇^2
function d end

#=function __init__()
@require Grassmann="4df31cd9-4c27-5bea-88d0-e6a7146666d8" include("grassmann.jl")
@require Reduce="93e0c654-6965-5f22-aba9-9c1ae6b3c259" include("symbolic.jl")
#@require SymPy="24249f21-da20-56a4-8eb1-6a02cf4ae2e6" nothing
end=#
Expand Down
13 changes: 0 additions & 13 deletions src/grassmann.jl

This file was deleted.

6 changes: 4 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Leibniz # Grassmann
using Leibniz, Grassmann
using Test

const V = V"3"

# write your own tests here
@test^2 == Δ
#@test value(V(∇)⋅V(∇)).expr == value((V(∇)^2)(0)(1)).expr
@test value(V(∇)V(∇)) == value((V(∇)^2)(0)(1))

2 comments on commit 6c3a635

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

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 Julia TagBot is installed, or can be done manually through the github interface, or via:

git tag -a v0.0.3 -m "<description of version>" 6c3a6356bc3635d75f350b7934a03704bc8181c8
git push origin v0.0.3

Please sign in to comment.