26 lines
904 B
Rust
26 lines
904 B
Rust
use std::cell::RefCell;
|
|
use std::rc::Rc;
|
|
use circuit_cas::circuit::probabilistic::ProbCircuit;
|
|
use circuit_cas::circuit::dag::CircuitExt;
|
|
|
|
fn main() {
|
|
let circuit: Rc<RefCell<ProbCircuit>> = ProbCircuit::new();
|
|
|
|
// vars accept anything that implements Into<StaticVar>: &'static str, (&str, u32), (&str, u32, u32)
|
|
let x = circuit.var("x");
|
|
let y = circuit.var(("y", 1)); // indexed variable y_1
|
|
let z = circuit.var(("z", 0, 1)); // doubly-indexed variable z_{0,1}
|
|
|
|
let x_plus_y = circuit.var("x") + y;
|
|
let x_plus_z = circuit.var("x") + z;
|
|
let expr = x_plus_y * x_plus_z;
|
|
|
|
// Deduplication: both x leaves share the same NodeId
|
|
let x2 = circuit.var("x");
|
|
assert_eq!(x.id, x2.id);
|
|
|
|
println!("(x + y_1) * (x + z_{{0,1}}) root node id: {:?}", expr.id);
|
|
println!("x node id: {:?}", x.id);
|
|
println!("x deduplicated node id: {:?}", x2.id);
|
|
}
|