improve api and simplify SumProdCircuit creation
This commit is contained in:
@@ -1,21 +1,22 @@
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
use circuit_cas::circuit::probabilistic::ProbCircuit;
|
||||
use circuit_cas::circuit::dag::CircuitExt;
|
||||
use circuit_cas::var;
|
||||
|
||||
fn main() {
|
||||
let circuit = ProbCircuit::new();
|
||||
let circuit: Rc<RefCell<ProbCircuit>> = ProbCircuit::new();
|
||||
|
||||
// Build (x + y) * (x + z)
|
||||
let x = circuit.leaf(var!("x"));
|
||||
let y = circuit.leaf(var!("y"));
|
||||
let z = circuit.leaf(var!("z"));
|
||||
let x = circuit.var("x");
|
||||
let y = circuit.var("y");
|
||||
let z = circuit.var("z");
|
||||
|
||||
let x_plus_y = circuit.leaf(var!("x")) + y;
|
||||
let x_plus_z = circuit.leaf(var!("x")) + z;
|
||||
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.leaf(var!("x"));
|
||||
let x2 = circuit.var("x");
|
||||
assert_eq!(x.id, x2.id);
|
||||
|
||||
println!("(x + y) * (x + z) root node id: {:?}", expr.id);
|
||||
|
||||
Reference in New Issue
Block a user