#diagram #bdd #syntax-tree #ast #expression-tree #anf

bin+lib bex

A rust library for working with boolean expressions (syntax trees, decision diagrams, algebraic normal form, etc.)

9 releases

new 0.3.0 Feb 17, 2025
0.2.0 Apr 22, 2023
0.1.7 Mar 27, 2023
0.1.5 May 21, 2021
0.1.0 Nov 30, 2018

#371 in Algorithms

Download history 40/week @ 2024-12-30

521 downloads per month

MIT license

740KB
10K SLoC

Rust 6K SLoC // 0.1% comments Vue 3.5K SLoC // 0.0% comments Python 146 SLoC // 0.4% comments Jupyter Notebooks 39 SLoC // 0.4% comments Shell 1 SLoC

bex : binary expression toolkit

Bex is a rust crate for working with binary (Boolean) expressions.

This crate lets you build a complicated abstract syntax tree (AST) by working with individual Bit structs, or vectors that act like integers.

You can also "solve" these AST structures by converting them into various canonical representations:

  • reduced, ordered, binary decision diagrams (ROBDDs) -- a normal form consisting of if-then-else triples that essentially act like compressed truth tables
  • algebraic nomal form -- an "xor of ands" polynomial form
  • (more coming in the future)

Video introduction

J and Bex vs Primorial 15 is about converting "simple" factoring problems into boolean expressions and solving them with bex.

It covers the large factoring problems in examples/solve/bdd-solve.rs and the smaller tests in src/solve.rs

Changes in main branch (upcoming version)

  • TBD

What's new in 0.3.0

  • Greatly expanded and fleshed out the python integration, including support for @tulip-control/dd
  • Added a variety of new functions to BddBase:
    • reorder for arbitrary reorderings
    • reorder_by_force for the FORCE algorith, a fast (but not always as effective) alternative to variable sifting
    • to_json and from_json to serialize and restore a set of nids
  • Added a simple HTTP API for integrating with other languages.
  • Added new Fun trait and NidFun struct, refining the idea of storing truth tables of up to 5 inputs in a NID.
  • Added ASTBase::{apply,eval}
  • naf.rs (a variation of ANF)
  • VhlSwarm (extracted a generic VHL swarm framework from BddSwarm, to re-use on other VHL-based mods)
  • Began standardizing the formatting/parsing of NIDs (FromStr and fmt::Display should now round-trip)
  • Many other small fixes and cleanups.

For full changelog, see CHANGELOG.md.

Dependencies

~3–8.5MB
~62K SLoC