Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix show method for DEC symbolics #80

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion src/symbolictheoryutils.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using MLStyle
using SymbolicUtils
using SymbolicUtils: Symbolic, BasicSymbolic, FnType, Sym, symtype
using SymbolicUtils: Symbolic, BasicSymbolic, FnType, Sym, symtype, issym
import SymbolicUtils: promote_symtype
import SymbolicUtils.show_call
import Base: nameof

function rules end
export rules
Expand Down Expand Up @@ -171,3 +173,34 @@ export @alias

alias(x) = error("$x has no aliases")
export alias

import Base.nameof
Base.nameof(f, arg, args...) = nameof(f)

function show_call(io, f, args)
fname = nameof(f, symtype.(args)...)
frep = Symbol(repr(f))
len_args = length(args)

if Base.isunaryoperator(frep) && len_args == 1
print(io, "$fname")
print_arg(io, first(args), paren=true)
elseif Base.isbinaryoperator(frep) && len_args > 1
for (i, t) in enumerate(args)
i != 1 && print(io, " $fname ")
print_arg(io, t, paren=true)
end
else
if issym(f)
Base.show_unquoted(io, nameof(f))
else
Base.show_unquoted(io, fname)
end
print(io, "(")
for i=1:len_args
print(io, args[i])
i != len_args && print(io, ", ")
end
print(io, ")")
end
end
11 changes: 11 additions & 0 deletions test/decasymbolic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -334,3 +334,14 @@ end
# Sum is (1, 6), (2, 10)

end

@testset "Printing" begin
@syms x::PrimalForm{1,:X,2}
@syms y::PrimalForm{1,:X,2}

buffer = IOBuffer()
print(buffer, Δ(x) + 2Δ(y))

res = String(take!(buffer))
@test res == "2Δ₁(y) + Δ₁(x)"
end
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ end
include("decasymbolic.jl")
end

include("aqua.jl")
# include("aqua.jl")
Loading