From a9561a1ad45a2b593f4e42b604c791dbdac97753 Mon Sep 17 00:00:00 2001 From: James Fairbanks Date: Wed, 25 Oct 2023 18:03:57 -0400 Subject: [PATCH] ENH: wip, convert from Decapodes to DecaExpr --- src/colanguage.jl | 52 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/colanguage.jl diff --git a/src/colanguage.jl b/src/colanguage.jl new file mode 100644 index 00000000..ad198034 --- /dev/null +++ b/src/colanguage.jl @@ -0,0 +1,52 @@ +using Decapodes +using Catlab +using Catlab.CategoricalAlgebra + +function Term(s::SummationDecapode) + judgements = map(parts(s,:Var)) do v + var = s[v, :name] + typ = s[v, :type] + Judgement(Var(var), typ, :X) + end + + op1s = map(parts(s, :Op1)) do op + x = Var(s[op, [:src, :name]]) + y = Var(s[op, [:tgt, :name]]) + f = s[op, :op1] + if f == :∂ₜ + y = Tan(y) + end + Eq(y, App1(f, x)) + end + + op2s = map(parts(s, :Op2)) do op + x = Var(s[op, [:proj1, :name]]) + y = Var(s[op, [:proj2, :name]]) + z = Var(s[op, [:res, :name]]) + f = s[op, :op2] + Eq(z, App2(f, x, y)) + end + + sums = map(parts(s, :Σ)) do σ + terms = map(Var, s[incident(s, σ, :summation), [:summand, :name]]) + Eq(Var(s[σ, [:sum,:name]]), Plus(terms)) + end + Decapodes.DecaExpr(judgements, vcat(op1s, op2s, sums)) +end + +dexp = parse_decapode(quote + A::Form0{X} + B::Form1{X} + C::Form0{X} + D::Form0{X} + + B == grad(A) + C == f(A,B) + ∂ₜ(A) == C + ∂ₜ(D) == C + D +end) + +d = SummationDecapode(dexp) + +dexpr′ = Term(d) +d′ = SummationDecapode(Term(d)) \ No newline at end of file