A categorical programming language
修订版 | f877dbc0f85c6e12ed2f9fbadabbcf4037ddb240 (tree) |
---|---|
时间 | 2022-03-15 14:29:41 |
作者 | Corbin <cds@corb...> |
Commiter | Corbin |
Generalize an optimization for pair/case.
@@ -1 +0,0 @@ | ||
1 | -(comp (pair fst fun/app-5) fun/app-5) |
@@ -1 +0,0 @@ | ||
1 | -(comp (pair fst fun/app-10) fun/app-10) |
@@ -1 +0,0 @@ | ||
1 | -(comp (pair fst fun/app-20) fun/app-20) |
@@ -1 +0,0 @@ | ||
1 | -(comp (pair fst fun/app-twice) fun/app-thrice) |
@@ -1 +0,0 @@ | ||
1 | -(comp (pair fst fun/app-40) fun/app-40) |
@@ -1,2 +0,0 @@ | ||
1 | -(comp (pair fst fun/app-twice) fun/app) | |
2 | - |
@@ -1 +0,0 @@ | ||
1 | -(comp (pair fst fun/app) fun/app) |
@@ -0,0 +1,3 @@ | ||
1 | +(case id id) | |
2 | + | |
3 | +The absolute value of an integer. |
@@ -58,8 +58,9 @@ fn main() -> std::io::Result<()> { | ||
58 | 58 | // pair-precompose when ?f and ?g are id |
59 | 59 | rw!("pair-factor-both"; "(pair ?r ?r)" => "(comp ?r (pair id id))"), |
60 | 60 | |
61 | - // Turn braided products into symmetric products. | |
62 | - rw!("pair-swap-invo"; "(comp (pair snd fst) (pair snd fst))" => "id"), | |
61 | + // This implies the old rule pair-swap-invo: (comp pair/swap pair/swap) => id | |
62 | + // So, like pair-swap-invo, this turns braided products into symmetric products. | |
63 | + rw!("pair-swap-pair"; "(comp (pair ?f ?g) (pair snd fst))" => "(pair ?g ?f)"), | |
63 | 64 | |
64 | 65 | // free for left |
65 | 66 | rw!("left-elim-case"; "(comp left (case ?f ?g))" => "?f"), |
@@ -67,6 +68,10 @@ fn main() -> std::io::Result<()> { | ||
67 | 68 | rw!("right-elim-case"; "(comp right (case ?f ?g))" => "?g"), |
68 | 69 | rw!("case-left-right"; "(case left right)" => "id"), |
69 | 70 | |
71 | + // dual of pair-swap-pair | |
72 | + // By abstract nonsense, this turns braided sums into symmetric sums. | |
73 | + rw!("case-swap-case"; "(comp (case right left) (case ?f ?g))" => "(case ?g ?f)"), | |
74 | + | |
70 | 75 | // dual of Elliott 2013 |
71 | 76 | rw!("case-postcompose"; "(case (comp ?f ?r) (comp ?g ?r))" => "(comp (case ?f ?g) ?r)"), |
72 | 77 | rw!("case-factor"; "(case ?r ?r)" => "(comp (case id id) ?r)"), |