Skip to content

Commit

Permalink
Merge pull request #73 from AlgebraicJulia/jpf/symbolictypes
Browse files Browse the repository at this point in the history
Bugfix to cm/symbolictypes
  • Loading branch information
quffaro authored Sep 10, 2024
2 parents 82f65ce + 4ba6dce commit e23459f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
8 changes: 5 additions & 3 deletions src/symbolictheoryutils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,13 @@ macro operator(head, body)
result = quote end

# construct the function on basic symbolics
argnames = [gensym(:x) for _ in 1:arity]
argclaus = [:($a::Symbolic) for a in argnames]
push!(result.args, quote
@nospecialize
function $f(args...)
s = promote_symtype($f, args...)
SymbolicUtils.Term{s}($f, [args...])
function $f($(argclaus...))
s = promote_symtype($f, $(argnames...))
SymbolicUtils.Term{s}($f, Any[$(argnames...)])
end
export $f
end)
Expand Down
34 changes: 25 additions & 9 deletions test/klausmeier.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,38 @@ end)

import .ThDEC: d, , SortError

@register Δ(s::Sort) begin
@match s begin
::Scalar => throw(SortError("Scalar"))
::VField => throw(SortError("Nay!"))
::Form => (d((d(s))))
end
end

ω, = @syms ω::PrimalFormT{1, :X, 2}

@test Δ(PrimalForm(1, X)) == PrimalForm(1, X)
@test symtype(Δ(ω)) == PrimalFormT{1, :X, 2}

# TODO propagating module information is suited for a macro
symbmodel = DecaSymbolic(lookup, Phytodynamics, Main)
symbmodel = ps = DecaSymbolic(lookup, Phytodynamics, Main)

DecaExpr(symbmodel)



n = ps.vars[1]
SymbolicUtils.symtype(n)
Δ(n)

r = @rule Δ(~n) => (d((d(~n))))

t2 = r(Δ(n))
t2 |> dump


using SymbolicUtils.Rewriters
using SymbolicUtils: promote_symtype
r = @rule ((~n)) => ~n
nested_star_cancel = Postwalk(Chain([r]))
nested_star_cancel(d(((n))))
nsc = nested_star_cancel

isequal(nsc(((d(n)))), d(n))
dump(nsc(((d(n)))))
dump(d(n))
((d(((n)))))
nsc(((d(((n))))))
nsc(nsc(((d(((n)))))))

0 comments on commit e23459f

Please sign in to comment.