open_hypergraphs/lax/var/mod.rs
1//! A higher-level interface for building lax Open Hypergraphs, including helpers to use *rust
2//! operators* like `+`, `&`, etc. to build terms.
3//! Here's an example of using this interface to build a "full adder" circuit.
4//!
5//! ```ignore
6//! fn full_adder(a: Var, b: Var, cin: Var) -> (Var, Var) {
7//! let a_xor_b = a.clone() ^ b.clone();
8//! let a_and_b = a & b;
9//!
10//! (a_xor_b, a_and_b)
11//! }
12//! ```
13//!
14//! This constructs a [`crate::lax::OpenHypergraph`] like the one below, where dashed lines
15//! indicate nodes connected by the quotient map.
16//!
17//! ```text
18//! ┌──────┐ ┌──────┐
19//! a │ ├───●╌╌╌╌╌●───┤ │ a ^ b
20//! ●───┤ Var │ │ XOR ├───●
21//! │ ├───● ●───┤ │
22//! └──────┘ \ / └──────┘
23//! \ /
24//! X
25//! / \
26//! ┌──────┐ / \ ┌──────┐
27//! b │ ├───● ●───┤ │ a & b
28//! ●───┤ Var │ │ AND ├───●
29//! │ ├───●╌╌╌╌╌●───┤ │
30//! └──────┘ x1 y1 └──────┘
31//! ```
32//!
33//! The purpose of a [`Var`] is to explicitly track variable usage:
34//! each time the var is used in an expression, a new node is created in the underlying
35//! OpenHypergraph, representing a *copy*.
36//! Note however that a [`Var`] correponds to a *hyperedge* rather than a node.
37//!
38//! See `examples/adder.rs` for a comprehensive example, including a definition of a simple
39//! language of simple digital circuits.
40
41mod operators;
42#[allow(clippy::module_inception)]
43mod var;
44
45pub mod forget;
46
47pub use operators::*;
48
49pub use var::*;