Module var

Source
Expand description

A higher-level interface for building lax Open Hypergraphs, including helpers to use rust operators like +, &, etc. to build terms. Here’s an example of using this interface to build a “full adder” circuit.

fn full_adder(a: Var, b: Var, cin: Var) -> (Var, Var) {
   let a_xor_b = a.clone() ^ b.clone();
   let a_and_b = a & b;

   (a_xor_b, a_and_b)
}

This constructs a crate::lax::OpenHypergraph like the one below, where dashed lines indicate nodes connected by the quotient map.

    ┌──────┐             ┌──────┐
a   │      ├───●╌╌╌╌╌●───┤      │    a ^ b
●───┤ Var  │             │ XOR  ├───●
    │      ├───●     ●───┤      │
    └──────┘    \   /    └──────┘
                 \ /
                  X
                 / \
    ┌──────┐    /   \    ┌──────┐
b   │      ├───●     ●───┤      │    a & b
●───┤ Var  │             │ AND  ├───●
    │      ├───●╌╌╌╌╌●───┤      │
    └──────┘   x1    y1  └──────┘

The purpose of a Var is to explicitly track variable usage: each time the var is used in an expression, a new node is created in the underlying OpenHypergraph, representing a copy. Note however that a Var correponds to a hyperedge rather than a node.

See examples/adder.rs for a comprehensive example, including a definition of a simple language of simple digital circuits.

Structs§

Var

Traits§

HasAdd
Vars can be added when the underlying signature has an operation for ‘addition’.
HasBitAnd
Vars support this operator when the underlying signature has the appropriate operation.
HasBitOr
Vars support this operator when the underlying signature has the appropriate operation.
HasBitXor
Vars can be added when the underlying signature has an operation for ‘addition’.
HasDiv
Vars support this operator when the underlying signature has the appropriate operation.
HasMul
Vars support this operator when the underlying signature has the appropriate operation.
HasNeg
Vars support this unary operator when the underlying signature has the appropriate operation.
HasNot
Vars support this unary operator when the underlying signature has the appropriate operation.
HasShl
Vars support this operator when the underlying signature has the appropriate operation.
HasShr
Vars support this operator when the underlying signature has the appropriate operation.
HasSub
Vars support this operator when the underlying signature has the appropriate operation.
HasVar

Functions§

operation
A general helper for constructing n → 1 maps