Skip to content

Commit

Permalink
trying to use symbolicutils export from #64
Browse files Browse the repository at this point in the history
  • Loading branch information
jpfairbanks committed Aug 26, 2024
1 parent 090ddfe commit 9e9d766
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/ThDEC.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export SpaceLookup

SpaceLookup(default::Space) = SpaceLookup(default, Dict{Symbol, Space}(nameof(default) => default))

@data Sort begin
@data Sort <: Number begin
Scalar()
Form(dim::Int, isdual::Bool, space::Space)
VField(isdual::Bool, space::Space)
Expand Down
4 changes: 4 additions & 0 deletions src/decasymbolic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,17 @@ Number(v::VField) = VFieldT{isdual(v), nameof(space(v)), dim(space(v))}

# for every unary operator in our theory, take a BasicSymbolic type, convert its type parameter to a Sort in our theory, and return a term
unop_dec = [:∂ₜ, :d, :★, :♯, :♭, :-]
# $unop(x) = FnType(unop, args)
for unop in unop_dec
@eval begin
@nospecialize
function ThDEC.$unop(
v::BasicSymbolic{T}
) where {T<:DECType}
# convert the DECType to ThDEC to type check
s = ThDEC.$unop(Sort(T))
# the resulting type is converted back to DECType
# the resulting term has the operation has its head and `v` as its args.
SymbolicUtils.Term{Number(s)}(ThDEC.$unop, [v])
end
end
Expand Down
4 changes: 2 additions & 2 deletions test/klausmeier.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ Phytodynamics = parse_decapode(quote
(n,w)::Form0
m::Constant

∂ₜ(n) == w - m*n + Δ(n)
∂ₜ(n) == w - m*n #+ Δ(n)
# ∂ₜ(n) == w * n*n - m*n + Δ(n)
end)

DecaSymbolic(lookup, Phytodynamics)
ps = DecaSymbolic(lookup, Phytodynamics)
52 changes: 52 additions & 0 deletions test/symbolicutils.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using SymbolicUtils
import SymbolicUtils: promote_symtype, symtype
using DiagrammaticEquations
using DiagrammaticEquations.ThDEC
using DiagrammaticEquations.SymbolicUtilsInterop
import DiagrammaticEquations.SymbolicUtilsInterop: DECType
using MLStyle

# Ω₀ = Form(0, false, Space(:X,1))
Ω₀ = FormT{0,false, :X, 1}
Ω₁ = FormT{1,false, :X, 1}
# @syms x f(x::Sort)::Sort
@syms x f(x::DECType)::DECType
@syms y::Ω₀ v::Ω₁

fdim(::FormT{i,isdual,space,dim}) where {i,isdual,space,dim} = i
isdual(::FormT{i,duality,space,dim}) where {i,duality,space,dim} = duality
spacename(::FormT{i,isdual,X,dim}) where {i,isdual,X,dim} = X
sdim(::FormT{i,isdual,space,dim}) where {i,isdual,space,dim} = dim

fdim(::PrimalFormT{i,space,dim}) where {i,space,dim} = i
isdual(::PrimalFormT{i,space,dim}) where {i,space,dim} = false
spacename(::PrimalFormT{i,X,dim}) where {i,X,dim} = X
sdim(::PrimalFormT{i,space,dim}) where {i,space,dim} = dim

function SymbolicUtils.promote_symtype(f::typeof(f), ::T) where T<: DECType
@show "Hit me"
FormT{fdim(T)+1, !isdual(T), spacename(T), sdim(T)}
end

# function SymbolicUtils.promote_symtype(f::typeof(f), ::FormT{i,isdual,space,dim}) where {i,isdual,space,dim}
# @show "Hit me"
# FormT{i+1, !isdual, space, dim}
# end

# function SymbolicUtils.promote_symtype(f::typeof(f), args...)
# @show args
# @match args[1] begin
# Scalar() => Scalar()
# FormT(&i, &isdual, &space, &dim) => FormT(i+1, isdual, space, dim)
# _ => error("type checking error for f")
# end
# end

using Test
@test_throws Exception f(x)
@test_throws Exception f(x)
# @less f(y)
symtype(f(y))
promote_symtype(f, symtype(y))
@syms x f(x::DECType)
promote_symtype(f, symtype(y))

0 comments on commit 9e9d766

Please sign in to comment.