Module var

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.

Modules§

forget
Forgetful functors for Var.

Structs§

Var

Traits§

HasAdd
Vars support this operator when the underlying signature has the appropriate operation.
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 XORed when the underlying signature has an operation for ‘xor’.
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§

build
Construct an OpenHypergraph from a function taking an empty OpenHypergraph, and returning two lists of Vars corresponding to sources and targets.
fn_operation
An n → 1 operation, returning its sole target Var.
operation
A general helper for constructing m → n maps

Type Aliases§

BuildResult