Skip to content

Commit 20cb73f

Browse files
committed
added targeted rotation simproc
1 parent 174aa96 commit 20cb73f

File tree

5 files changed

+49
-1
lines changed

5 files changed

+49
-1
lines changed

simprocs/basic_simp.ML

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
(* normalises w.r.t. to the terminating/confluent fragment of the ZX-calculus,
2+
* see e.g. http://www.cs.ox.ac.uk/people/bob.coecke/Aleks.pdf *)
13
open RG_SimpUtil
24

35

@@ -22,3 +24,5 @@ register_simproc ("basic_simp", REDUCE_ALL simps);
2224

2325

2426

27+
28+

simprocs/rotate_simp.ML

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
(* naive simproc using the "rotate" rule to reduce to pseudo-normal form
2+
* for phase-free graphs *)
13
open RG_SimpUtil
24

35
val rotate = load_rule "theorems/rotate";
@@ -33,3 +35,4 @@ register_simproc ("rotate_simp", simproc);
3335

3436

3537

38+

simprocs/rotate_targeted.ML

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
(* improved simproc using the rotate rule to reduce to pseudo-normal form
2+
* for phase-free graphs *)
3+
open RG_SimpUtil
4+
5+
val rotate = load_rule "theorems/rotate_targeted";
6+
val green_ids = load_rule "theorems/green_id_on_red";
7+
val green_elim = load_rule "theorems/green_elim";
8+
val green_scalar = load_rule "axioms/green_scalar";
9+
val simps = load_ruleset [
10+
"axioms/red_copy", "axioms/red_sp", "axioms/green_sp", "axioms/hopf",
11+
"axioms/red_scalar", "axioms/green_scalar", "axioms/green_id",
12+
"axioms/red_id", "axioms/red_loop", "axioms/green_loop"];
13+
14+
val targetf = min_arity_vertex_where is_interior_green
15+
fun target_arity g = case targetf g of SOME v => arity g v | NONE => 0
16+
fun target_with_arity a = vertex_where (fn g => fn v =>
17+
is_interior_green g v andalso arity g v = a)
18+
19+
val simproc = (
20+
REDUCE_ALL simps ++
21+
REDUCE_METRIC_TO 0 num_boundary_red green_ids ++
22+
LOOP (
23+
LOOP_WHILE (fn g => target_arity g >= 2)
24+
(REWRITE_TARGETED { PATTERN = const_vertex "v10",
25+
TARGET = targetf } rotate) ++
26+
LOOP (
27+
REWRITE_TARGETED { PATTERN = const_vertex "v10",
28+
TARGET = target_with_arity 1 } green_elim ++
29+
REDUCE green_scalar)
30+
) ++
31+
REDUCE_ALL simps
32+
);
33+
34+
register_simproc ("rotate_targeted", simproc);
35+
36+
37+
38+
39+
40+

theorems/green_elim.qrule

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"lhs":{"bang_boxes":{"bx0":{"contents":["b0","v0"]},"bx1":{"contents":["b0"],"parent":"bx0"}},"wire_vertices":{"b0":{"annotation":{"boundary":true,"coord":[0.0,-2.0]}}},"node_vertices":{"v0":{"annotation":{"coord":[0.0,-0.5]}},"v1":{"annotation":{"coord":[0.0,3.0]}},"v2":{"data":{"type":"X","value":""},"annotation":{"coord":[0.0,1.5]}}},"undir_edges":{"e0":{"src":"v1","tgt":"v2"},"e1":{"src":"v2","tgt":"v0"},"e2":{"src":"v0","tgt":"b0"}}},"rhs":{"bang_boxes":{"bx0":{"contents":["b0","v4"]},"bx1":{"contents":["b0"],"parent":"bx0"}},"wire_vertices":{"b0":{"annotation":{"boundary":true,"coord":[0.0,-2.0]}}},"node_vertices":{"v4":{"annotation":{"coord":[-0.0030441242608455848,-0.8107430454299842]}}},"undir_edges":{"e4":{"src":"v4","tgt":"b0"}}},"derivation":"derivations/green_elim"}
1+
{"lhs":{"bang_boxes":{"bx0":{"contents":["b0","v0"]},"bx1":{"contents":["b0"],"parent":"bx0"}},"wire_vertices":{"b0":{"annotation":{"boundary":true,"coord":[-0.02,-1.69]}}},"node_vertices":{"v10":{"annotation":{"coord":[0.0,3.25]}},"v0":{"annotation":{"coord":[0.0,-0.57]}},"v2":{"data":{"type":"X","value":""},"annotation":{"coord":[0.02,1.41]}}},"undir_edges":{"e1":{"src":"v2","tgt":"v0"},"e2":{"src":"v0","tgt":"b0"},"e3":{"src":"v2","tgt":"v10"}}},"rhs":{"bang_boxes":{"bx0":{"contents":["b0","v0"]},"bx1":{"contents":["b0"],"parent":"bx0"}},"wire_vertices":{"b0":{"annotation":{"boundary":true,"coord":[0.02,-1.81]}}},"node_vertices":{"v0":{"annotation":{"coord":[0.0,-0.71]}}},"undir_edges":{"e0":{"src":"v0","tgt":"b0"}}}}

theorems/rotate_targeted.qrule

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"lhs":{"bang_boxes":{"bx5":{"contents":["b2"],"parent":"bx2"},"bx0":{"contents":["b0","v0"]},"bx6":{"contents":["b3"]},"bx4":{"contents":["b1"],"parent":"bx1"},"bx3":{"contents":["b0"],"parent":"bx0"},"bx1":{"contents":["b1","v1"]},"bx2":{"contents":["b2","v2"]}},"wire_vertices":{"b1":{"annotation":{"boundary":true,"coord":[-2.25,-3.0]}},"b0":{"annotation":{"boundary":true,"coord":[0.0,4.25]}},"b2":{"annotation":{"boundary":true,"coord":[2.25,-2.75]}},"b3":{"annotation":{"boundary":true,"coord":[-2.5,4.25]}}},"node_vertices":{"v2":{"annotation":{"coord":[2.0,-1.75]}},"v5":{"data":{"type":"X","value":""},"annotation":{"coord":[1.0,0.25]}},"v1":{"annotation":{"coord":[-1.75,-1.5]}},"v4":{"data":{"type":"X","value":""},"annotation":{"coord":[-1.0,0.25]}},"v0":{"annotation":{"coord":[0.0,2.5]}},"v10":{"annotation":{"coord":[-2.5,2.5]}}},"undir_edges":{"e6":{"src":"v1","tgt":"b1"},"e1":{"src":"v0","tgt":"v4"},"e5":{"src":"v2","tgt":"b2"},"e7":{"src":"v4","tgt":"v10"},"e0":{"src":"b0","tgt":"v0"},"e4":{"src":"v5","tgt":"v2"},"e8":{"src":"v5","tgt":"v10"},"e3":{"src":"v0","tgt":"v5"},"e9":{"src":"v10","tgt":"b3"},"e2":{"src":"v4","tgt":"v1"}}},"rhs":{"bang_boxes":{"bx5":{"contents":["b2"],"parent":"bx2"},"bx0":{"contents":["b0","v1"]},"bx6":{"contents":["b3"]},"bx4":{"contents":["b1"],"parent":"bx1"},"bx3":{"contents":["b0"],"parent":"bx0"},"bx1":{"contents":["b1","v0"]},"bx2":{"contents":["b2","v2"]}},"wire_vertices":{"b1":{"annotation":{"boundary":true,"coord":[-1.75,-2.75]}},"b0":{"annotation":{"boundary":true,"coord":[0.0,3.0]}},"b2":{"annotation":{"boundary":true,"coord":[1.5,-2.5]}},"b3":{"annotation":{"boundary":true,"coord":[-2.0,3.25]}}},"node_vertices":{"v2":{"annotation":{"coord":[1.25,-1.0]}},"v1":{"annotation":{"coord":[-0.0,1.75]}},"v4":{"data":{"type":"X","value":""},"annotation":{"coord":[0.75,0.25]}},"v0":{"annotation":{"coord":[-1.5,-1.0]}},"v3":{"data":{"type":"X","value":""},"annotation":{"coord":[-0.25,-1.0]}},"v10":{"annotation":{"coord":[-2.0,1.75]}}},"undir_edges":{"e6":{"src":"v3","tgt":"v2"},"e1":{"src":"v1","tgt":"v4"},"e5":{"src":"v0","tgt":"v3"},"e7":{"src":"v4","tgt":"v10"},"e0":{"src":"b0","tgt":"v1"},"e4":{"src":"v0","tgt":"b1"},"e8":{"src":"v10","tgt":"b3"},"e3":{"src":"v2","tgt":"b2"},"e2":{"src":"v4","tgt":"v2"}}}}

0 commit comments

Comments
 (0)