Skip to content

Commit

Permalink
ensure symbolic functions work on Chain, MultiVector and Simplex objects
Browse files Browse the repository at this point in the history
  • Loading branch information
micahscopes committed Apr 23, 2020
1 parent faac7d9 commit f10c276
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/Grassmann.jl
Expand Up @@ -255,7 +255,7 @@ function __init__()
end
@require SymPy="24249f21-da20-56a4-8eb1-6a02cf4ae2e6" begin
generate_algebra(:SymPy,:Sym,:diff,:symbols)
T = Union{TensorTerm, TensorMixed}
T = Union{TensorGraded, TensorMixed}
symbolic = v -> typeof(v) == SymPy.Sym
SymPy.expand(x::T) = map(v -> symbolic(v) ? SymPy.expand(v) : v, x)
SymPy.factor(x::T) = map(v -> symbolic(v) ? SymPy.factor(v) : v, x)
Expand All @@ -269,7 +269,7 @@ function __init__()
end
@require SymEngine="123dc426-2d89-5057-bbad-38513e3affd8" begin
generate_algebra(:SymEngine,:Basic,:diff,:symbols)
T = Union{TensorTerm, TensorMixed}
T = Union{TensorGraded, TensorMixed}
symbolic = v -> typeof(v) == SymEngine.Basic
SymEngine.expand(x::T) = map(v -> symbolic(v) ? SymEngine.expand(v) : v, x)
SymEngine.subs(x::T, args...) = map(v -> symbolic(v) ? SymEngine.subs(v, args...) : v, x)
Expand Down
7 changes: 6 additions & 1 deletion test/symbolictests.jl
@@ -1,6 +1,6 @@

"""
Test symbolic expressions.
Smoke tests for common SymPy and SymEngine functions.
"""
module SymbolicTests
using Grassmann
Expand All @@ -11,12 +11,17 @@ using Grassmann
@basis S"+++"
x,y,z = SymEngine.symbols("x y z")

# expanding the symbolic coefficient of a `Simplex`
simp = (x+1)^2*v1
@show SymEngine.expand(simp)

# expansion/substitution on each symbolic coefficient of a `MultiVector`
mv = (x+y)^3 * v12 + (y+z) * v123
@show SymEngine.subs(mv, Dict(x=>2, y=>2, z=>2))
@show SymEngine.expand(mv)

# expanding each symbolic coefficient of a `Chain`
@show expand((x+1)*(x+2)*(v1+v2))
end

@testset "Test SymPy" begin
Expand Down

0 comments on commit f10c276

Please sign in to comment.