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
Rewrite rule for removing redundant swaps #57
Comments
You can translate your diagram back and forth the from discopy import Ty, Id, Swap, hypergraph
x = Ty("x")
back_n_forth = lambda f: hypergraph.Diagram.upgrade(f).downgrade()
assert back_n_forth(Swap(x, x) >> Swap(x, x)) == Id(x @ x) The only price to pay is that hypergraph categories are self-adjoint so this will remove all the adjoints from your diagram (i.e. |
What if we wrapped all the types? @toumix |
The problem comes from the greedy algorithm used for the "forth" part of I don't think there is an obvious way to solve this problem. Planarity testing for graphs is a non-trivial problem, it can be solved in linear time but this requires some clever data structures. Adapting those data structures to diagrams, represented as graphs with extra structure, sounds like a very cool project but maybe it's a bit too much effort for the expected payoff. |
Maybe the diagrams you are trying to simplify have some special shape for which a simple heuristic can do the trick? In your example it would make sense to add the new boxes to the right hand side instead, this would be very easy to implement. |
Can you share a code snippet for adding new boxes to the right instead? |
I'm busy with other things right now but you can try replacing this one line: https://github.com/oxford-quantum-group/discopy/blob/87dcd350480532b616eb7acf9043ab94b8300c70/discopy/drawing.py#L223 with box, offset = box_node.box, getattr(box_node, "offset", len(scan)) |
Even better, you could submit a PR for a new optional argument to |
Thanks, I will look into it |
I am wondering if discopy has any rewriting tools for removing redundant swaps? Specifically, I am trying to automatically remove this kind of redundant swaps:
which is, I believe, equivalent to the followings up to symmetries:
The text was updated successfully, but these errors were encountered: