Catlab.jl icon indicating copy to clipboard operation
Catlab.jl copied to clipboard

Codiagonals in @program macro that are not returned

Open kris-brown opened this issue 4 years ago • 2 comments

The @program macro allows for very easy wiring directed wiring diagram generation, but there are certain wiring diagrams it cannot express. For example, I'd like the following program to return a and merge inputs b and c

@program C (a::X,b::X,c::X) begin 
       [b, c]
       return a 
 end

However, it just returns a. Any codiagonal that doesn't somehow make it to the final return expression gets ignored, it seems.

@program C (a::X,b::X,c::X) begin 
       return (a,  [b, c])
 end

This program almost gives us what we want, but it has b (which equals c) as an output that we don't want. A current workaround is to generate wiring diagrams like this and then trim off outputs that weren't actually desired from the ACSet.

(There's a dual issue when we want to create cups rather than caps, requiring us to create artificial inputs which then must be 'trimmed' at the end, too.)

kris-brown avatar Sep 22 '21 18:09 kris-brown

The reason for this that the @program macro assumes that the biproduct laws are in effect when combining the product and coproduct structures. (I'm not sure whether this is documented.) The law at work here is

Screenshot from 2021-09-22 15-02-04

which says that merging and then deleting is the same as just deleting the two inputs. So what you are seeing is expected behavior.

We could have a variant of the program macro with different behavior. It sounds like you are asking for a version where you can express caps and cups?

epatters avatar Sep 22 '21 22:09 epatters

Make sense! And yeah, that sounds right. So this is definitely more of a feature request than a bug.

kris-brown avatar Sep 23 '21 13:09 kris-brown