mod tests; use crate::ast::Node; // fn cancel_double_negation(ast: &mut Node, parent: Option<&mut Node>) -> Node { // match ast { // Node::Unary { operator: _, operand } => { // if let Some(node) = parent { // } else { // *ast = cancel_double_negation(&mut *operand, Some(ast)); // } // }, // Node::Binary { operator: _, lhs, rhs } => { // *ast = cancel_double_negation(&mut *lhs, None); // *ast = cancel_double_negation(&mut *rhs, None); // }, // Node::Leaf(c) => (), // } // ast // } // fn cancel_double_negation(ast: Node) { // let mut new_ast = ast.clone(); // fn recursion(ast: &mut Node, node_count: usize) { // match ast { // Node::Unary { operator: _, operand } => { // recursion(&mut *operand, node_count + 1); // }, // Node::Binary { operator: _, lhs, rhs } => { // recursion(&mut *lhs, node_count + 1); // recursion(&mut *rhs, node_count + 1); // }, // Node::Leaf(c) => (), // } // } // recursion(&mut new_ast, 0); // new_ast // } fn negation_normal_form(formula: &str) -> String { let mut ast = Node::::parse_formula(formula); // let mut tmp = Node::::parse_formula((formula.to_string() + "!").as_str()); // let mut clone = ast.clone(); // while Node::::ast_to_formula(&clone) != Node::::ast_to_formula(&tmp) { // let copy = ast.clone(); // clone = ast.clone(); // dbg!(&ast); // tmp = match copy { // Node::Unary { operator: _, operand } => { // match *operand { // Node::Unary { operator: _, operand } => { // println!("salut"); // dbg!(&*operand); // *operand // } // Node::Binary { operator: _, lhs: _, rhs: _ } => ast, // Node::Leaf(_) => ast, // } // } // Node::Binary { operator: _, lhs: _, rhs: _ } => ast, // Node::Leaf(_) => ast, // }; // ast = tmp.clone(); // } ast.simplify(); Node::::ast_to_formula(&ast) }