AlgebraicJulia / Decapodes.jl

A framework for composing and simulating multiphysics systems
https://algebraicjulia.github.io/Decapodes.jl/dev/
MIT License
49 stars 14 forks source link

Use new match-replace operator aliasing #252

Open lukem12345 opened 3 months ago

lukem12345 commented 3 months ago

Currently, each operator that can be expanded into its definition is expanded with bespoke operations on Decapodes:

function add_Codiff!(d::SummationDecapode, src_Codiff::Int, tgt_Codiff::Int)
  hodge_star_first = add_part!(d, :Var, type=:infer, name=nothing)
  add_part!(d, :Op1, src=src_Codiff, tgt=hodge_star_first, op1=:⋆)

  exterior_deriv = add_part!(d, :Var, type=:infer, name=nothing)
  add_part!(d, :Op1, src=hodge_star_first, tgt=exterior_deriv, op1=:d)

  add_part!(d, :Op1, src=exterior_deriv, tgt=tgt_Codiff, op1=:⋆)
end

However, PR #37 of DiagrammaticEquations.jl added support for a Match-Replacement approach. This silos imperative pointer-manipulation logic, and provides a declarative interface. “Matches” can be Symbols or Decapodes, and can be replaced with “Replacement” Symbols or Decapodes:

  RHS = @decapode begin
    y == ∘(⋆,d,⋆)(X)
  end
  replace_op1!(MyDecapode, :div, RHS)

So, we should establish a library of definitions in DiagrammaticEquations.jl, and use that functionality in the Decapodes compiler.

lukem12345 commented 1 month ago

To clarify some language:

DiagrammaticEquations.jl PR 37 implemented a rewrite system (see e.g. Bonchi et al. for an overview), specialized to the case in which signatures are of arity 1 (corresponding to our Op1s) or arity 2 (corresponding to our Op2s) and are all of co-arity 1.

When I say "a Match-Replacement approach", I mean a term rewrite system. When I say "establish a library of definitions", I mean define a collection of rewrite rules.