Skip to content

Commit 5f51ab6

Browse files
authored
Rewriting with Symmetric Monoidal Structure (#27)
Implement rewriting with symmetric monoidal structure Bonchi, Filippo, et al. "String diagram rewrite theory II: Rewriting with symmetric monoidal structure." Mathematical Structures in Computer Science 32.4 (2022): 511-541. # Details - implement rewrite with SMT - apply_smc_rewrite takes as arguments "witnesses" that inputs are legal, witnesses are implemented in previous PRs. - We work on strict because some properties requires quotiented wires - Some tests using circuits and compiler-like optimizations (dead code elimination, constant propagation) - Refactoring for reuse existing checks without cloning.
1 parent 3bee5a9 commit 5f51ab6

11 files changed

Lines changed: 2504 additions & 134 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ serde = { version = "1.0", features = ["derive"], optional = true }
1414
[features]
1515
default = []
1616
serde = ["dep:serde"]
17+
experimental = []
1718

1819
[dev-dependencies]
1920
proptest = "1.6.0"

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,23 @@ This code is an implementation of the paper
2828
- Functors, including optic transformation for ahead-of-time differentiation of
2929
syntax
3030

31+
# Experimental APIs
32+
33+
Some APIs are marked experimental and are disabled by default.
34+
35+
Enable experimental APIs with Cargo features:
36+
37+
```toml
38+
[dependencies]
39+
open-hypergraphs = { version = "0.2.10", features = ["experimental"] }
40+
```
41+
42+
or on the command line:
43+
44+
```bash
45+
cargo test --features experimental
46+
```
47+
3148
# Examples
3249

3350
An example for defining a simple expression language ([polynomial

src/array/traits.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ pub trait Array<K: ArrayKind, T>: Clone {
7878
/// Concatenate two arrays
7979
fn concatenate(&self, other: &Self) -> Self;
8080

81+
/// Concatenate a slice of arrays into one array.
82+
fn concatenate_many(arrays: &[&Self]) -> Self;
83+
8184
/// `fill(x, n)` returns the array length n containing repeated element x.
8285
fn fill(x: T, n: K::I) -> Self;
8386

src/array/vec/vec_array.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,23 @@ impl<T: Clone> Array<VecKind, T> for VecArray<T> {
6868
VecArray(result)
6969
}
7070

71+
fn concatenate_many(arrays: &[&Self]) -> Self {
72+
if arrays.is_empty() {
73+
return Self::empty();
74+
}
75+
76+
let mut n = 0;
77+
for arr in arrays {
78+
n += arr.len();
79+
}
80+
81+
let mut out = Vec::with_capacity(n);
82+
for arr in arrays {
83+
out.extend_from_slice(arr);
84+
}
85+
Self(out)
86+
}
87+
7188
fn fill(x: T, n: usize) -> Self {
7289
VecArray(vec![x; n])
7390
}

0 commit comments

Comments
 (0)