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

Morphisms as programs #52

Closed
epatters opened this issue Nov 13, 2019 · 3 comments
Closed

Morphisms as programs #52

epatters opened this issue Nov 13, 2019 · 3 comments

Comments

@epatters
Copy link
Member

epatters commented Nov 13, 2019

We want a module for converting morphisms in a symmetric monoidal category to and from programs, by which I mean expressions with variables in the style of type theory. This module will replace what is currently called Catlab.Algebra (#37), and will be called something like Catlab.Programs.

Desired features:

I will follow up shortly with ideas about design and implementation.

@epatters
Copy link
Member Author

epatters commented Nov 14, 2019

First, a comment about design. Coincidentally, Mike Shulman has recently published a preprint about a type theory for symmetric monoidal categories. There is a lot going on there, much of which I haven't fully understood, but the discussion in Section 1 is good food for thought.

One relevant issue that Shulman raises is how to deal with monoidal products in the codomain. Suppose you have morphisms f: W -> X x Y and g: X x Y -> Z. How do you write the composite of f with g? Shulman proposes an indexing notation inspired by Sweedler notation, but I think in Julia it will be more natural to write

x, y = f(w)
g(x,y)

(in the spirit of what Shulman calls "covariables") or simply

g(f(w))

Ordinarily, in Julia, only one of these invocations would be allowed. This is the difference between g(x,y) and g((x,y)). For the purpose of parsing Julia programs into morphisms, I think we should allow both. We can do so unambiguously because the morphisms are statically typed. If I understand correctly, Shulman also allows both styles of composition, albeit using the Sweedler notation (see the last two term constructors in Fig 4).

Apart from this subtlety about multiple outputs, and a similar one about nullary outputs (monoidal units), I think we can stick to the ordinary semantics of Julia code.

@epatters
Copy link
Member Author

epatters commented Nov 14, 2019

One way to implement this is to rewrite the Julia program so that:

  1. variables carry ports in a wiring diagram
  2. function calls create a new box and return its output ports.

The program can then be executed by the Julia run-time and the result will be a wiring diagram.

epatters added a commit that referenced this issue Nov 14, 2019
epatters added a commit that referenced this issue Nov 14, 2019
epatters added a commit that referenced this issue Nov 14, 2019
epatters added a commit that referenced this issue Nov 14, 2019
epatters added a commit that referenced this issue Nov 15, 2019
The idea is to separate the generic (non-numerical) and the numerical parts
of the current algebraic nets codebase to get a general-purpose code
generation system, of which algebraic nets will be a special case.

A first pass. More refactoring will probably follow. Towards #52.
epatters added a commit that referenced this issue Nov 15, 2019
We already had this functionality for algebraic networks, but now it is
more generic. Towards #52.
epatters added a commit that referenced this issue Nov 15, 2019
Again, we already had this functionality for algebraic networks, but
now it is more general.
epatters added a commit that referenced this issue Nov 17, 2019
@epatters
Copy link
Member Author

epatters commented Nov 17, 2019

This issue is now mostly resolved. The only outstanding feature is recovering morphism expressions from traditional expression trees (Formula), but I'll defer that to another issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant