From 9e9d766680422515999a3d43c5e721a02dd83189 Mon Sep 17 00:00:00 2001 From: James Fairbanks Date: Mon, 26 Aug 2024 16:06:47 -0400 Subject: [PATCH] trying to use symbolicutils export from #64 --- src/ThDEC.jl | 2 +- src/decasymbolic.jl | 4 ++++ test/klausmeier.jl | 4 ++-- test/symbolicutils.jl | 52 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 test/symbolicutils.jl diff --git a/src/ThDEC.jl b/src/ThDEC.jl index 91dcbe4..259e9c7 100644 --- a/src/ThDEC.jl +++ b/src/ThDEC.jl @@ -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) diff --git a/src/decasymbolic.jl b/src/decasymbolic.jl index d3a9f86..0196167 100644 --- a/src/decasymbolic.jl +++ b/src/decasymbolic.jl @@ -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 diff --git a/test/klausmeier.jl b/test/klausmeier.jl index b44d754..c705251 100644 --- a/test/klausmeier.jl +++ b/test/klausmeier.jl @@ -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) \ No newline at end of file +ps = DecaSymbolic(lookup, Phytodynamics) \ No newline at end of file diff --git a/test/symbolicutils.jl b/test/symbolicutils.jl new file mode 100644 index 0000000..6b47d72 --- /dev/null +++ b/test/symbolicutils.jl @@ -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)) \ No newline at end of file