diff --git a/src/DiagrammaticEquations.jl b/src/DiagrammaticEquations.jl index 0ef26a9..72cada6 100644 --- a/src/DiagrammaticEquations.jl +++ b/src/DiagrammaticEquations.jl @@ -69,8 +69,6 @@ include("graph_traversal.jl") include("deca/Deca.jl") include("learn/Learn.jl") include("SymbolicUtilsInterop.jl") -include("ThDEC.jl") -include("decasymbolic.jl") include("acset2symbolic.jl") @reexport using .Deca diff --git a/src/acset2symbolic.jl b/src/acset2symbolic.jl index 63c3ff2..f84b3f2 100644 --- a/src/acset2symbolic.jl +++ b/src/acset2symbolic.jl @@ -4,9 +4,7 @@ using SymbolicUtils.Rewriters using SymbolicUtils.Code using MLStyle -import DiagrammaticEquations.ThDEC: Space - -export extract_symexprs, apply_rewrites, merge_equations +export extract_symexprs, apply_rewrites, merge_equations, to_acset const DECA_EQUALITY_SYMBOL = (==) @@ -17,8 +15,8 @@ function to_symbolics(d::SummationDecapode, op_index::Int, ::Val{:Op1}) output_sym = SymbolicUtils.Sym{Number}(d[d[op_index, :tgt], :name]) op_sym = SymbolicUtils.Sym{(SymbolicUtils.FnType){Tuple{Number}, Number}}(d[op_index, :op1]) - input_sym = setmetadata(input_sym, Sort, oldtype_to_new(d[d[op_index, :src], :type])) - output_sym = setmetadata(output_sym, Sort, oldtype_to_new(d[d[op_index, :tgt], :type])) + # input_sym = setmetadata(input_sym, Sort, oldtype_to_new(d[d[op_index, :src], :type])) + # output_sym = setmetadata(output_sym, Sort, oldtype_to_new(d[d[op_index, :tgt], :type])) rhs = SymbolicUtils.Term{Number}(op_sym, [input_sym]) SymbolicUtils.Term{Number}(DECA_EQUALITY_SYMBOL, [output_sym, rhs]) @@ -30,9 +28,9 @@ function to_symbolics(d::SummationDecapode, op_index::Int, ::Val{:Op2}) output_sym = SymbolicUtils.Sym{Number}(d[d[op_index, :res], :name]) op_sym = SymbolicUtils.Sym{(SymbolicUtils.FnType){Tuple{Number, Number}, Number}}(d[op_index, :op2]) - input1_sym = setmetadata(input1_sym, Sort, oldtype_to_new(d[d[op_index, :proj1], :type])) - input2_sym = setmetadata(input2_sym, Sort, oldtype_to_new(d[d[op_index, :proj2], :type])) - output_sym = setmetadata(output_sym, Sort, oldtype_to_new(d[d[op_index, :res], :type])) + # input1_sym = setmetadata(input1_sym, Sort, oldtype_to_new(d[d[op_index, :proj1], :type])) + # input2_sym = setmetadata(input2_sym, Sort, oldtype_to_new(d[d[op_index, :proj2], :type])) + # output_sym = setmetadata(output_sym, Sort, oldtype_to_new(d[d[op_index, :res], :type])) rhs = SymbolicUtils.Term{Number}(op_sym, [input1_sym, input2_sym]) SymbolicUtils.Term{Number}(DECA_EQUALITY_SYMBOL, [output_sym, rhs]) @@ -43,20 +41,20 @@ end # Expr(EQUALITY_SYMBOL, c.output, Expr(:call, Expr(:., :+), c.inputs...)) # end -function oldtype_to_new(old::Symbol, space::Space = Space(:I, 2))::Sort - @match old begin - :Form0 => PrimalForm(0, space) - :Form1 => PrimalForm(1, space) - :Form2 => PrimalForm(2, space) +# function oldtype_to_new(old::Symbol, space::Space = Space(:I, 2))::Sort +# @match old begin +# :Form0 => PrimalForm(0, space) +# :Form1 => PrimalForm(1, space) +# :Form2 => PrimalForm(2, space) - :DualForm0 => DualForm(0, space) - :DualForm1 => DualForm(1, space) - :DualForm2 => DualForm(2, space) +# :DualForm0 => DualForm(0, space) +# :DualForm1 => DualForm(1, space) +# :DualForm2 => DualForm(2, space) - :Constant => Scalar() - :Parameter => Scalar() - end -end +# :Constant => Scalar() +# :Parameter => Scalar() +# end +# end function extract_symexprs(d::SummationDecapode) topo_list = topological_sort_edges(d) @@ -88,7 +86,7 @@ function merge_equations(d::SummationDecapode, rewritten_syms) for node in start_nodes(d) sym = SymbolicUtils.Sym{Number}(d[node, :name]) - sym = setmetadata(sym, Sort, oldtype_to_new(d[node, :type])) + # sym = setmetadata(sym, Sort, oldtype_to_new(d[node, :type])) push!(lookup, (sym => sym)) end @@ -148,8 +146,3 @@ function to_acset(og_d, sym_exprs) d end - -# TODO: We need a way to get information like the d and ⋆ even when not in the ACSet -# @syms Δ(x) d(x) ⋆(x) -# lap_0_rule = @rule Δ(~x) => ⋆(d(⋆(d(~x)))) -# rewriter = Postwalk(RestartedChain([lap_0_rule])) diff --git a/src/sym_rewrite.jl b/src/sym_rewrite.jl index 6dff12a..de21b89 100644 --- a/src/sym_rewrite.jl +++ b/src/sym_rewrite.jl @@ -2,10 +2,6 @@ using DiagrammaticEquations using SymbolicUtils using MLStyle -test_space = Space(:X, 2) - -test_type = Form(0, false, test_space) - Heat = @decapode begin C::Form0 D::Constant @@ -15,18 +11,6 @@ end infer_types!(Heat) resolve_overloads!(Heat) -function isform_zero(x) - getmetadata(x, Sort).dim == 0 -end - -function isform_one(x) - getmetadata(x, Sort).dim == 1 -end - -function isform_two(x) - getmetadata(x, Sort).dim == 2 -end - @syms Δ(x) d(x) ⋆(x) Δ₀(x) Δ₁(x) Δ₂(x) d₀(x) lap_0_convert = @rule Δ₀(~x) => Δ(~x) @@ -37,9 +21,9 @@ d_0_convert = @rule d₀(~x) => d(~x) overloaders = [lap_0_convert, lap_1_convert, lap_2_convert, d_0_convert] -lap_0_rule = @rule Δ(~x::(isform_zero)) => ⋆(d(⋆(d(~x)))) -lap_1_rule = @rule Δ(~x::(isform_one)) => d(⋆(d(⋆(~x)))) + ⋆(d(⋆(d(~x)))) -lap_2_rule = @rule Δ(~x::(isform_two)) => d(⋆(d(⋆(~x)))) +lap_0_rule = @rule Δ(~x) => ⋆(d(⋆(d(~x)))) +lap_1_rule = @rule Δ(~x) => d(⋆(d(⋆(~x)))) + ⋆(d(⋆(d(~x)))) +lap_2_rule = @rule Δ(~x) => d(⋆(d(⋆(~x)))) openers = [lap_0_rule, lap_1_rule, lap_2_rule] @@ -61,18 +45,6 @@ optm_rewriter = SymbolicUtils.Postwalk( res_merge_exprs = map(optm_rewriter, merge_exprs) -final_exprs = SymbolicUtils.Code.toexpr.(res_merge_exprs) -map(x -> x.args[1] = :(==), final_exprs) - -to_decapode = quote - C::Form0 - D::Constant - Ċ::Form0 -end - -append!(to_decapode.args, final_exprs) - -test = parse_decapode(to_decapode) -deca_test = SummationDecapode(test) +deca_test = to_acset(Heat, res_merge_exprs) infer_types!(deca_test) resolve_overloads!(deca_test)