From e3c75ec22b91bce1758afb1a37c61a4cb1e0feed Mon Sep 17 00:00:00 2001 From: mehbark Date: Tue, 13 Jun 2023 22:54:36 -0400 Subject: [PATCH] remove early return when there is no change in simp --- src/main.rs | 27 +++------------------------ 1 file changed, 3 insertions(+), 24 deletions(-) diff --git a/src/main.rs b/src/main.rs index 00ba605..40d8b12 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,7 +3,6 @@ use std::{ collections::{HashMap, HashSet}, env, io::{self, Read}, - iter, sync::Mutex, }; @@ -598,14 +597,7 @@ fn rw(rule: &Rule, sexp: &Sexp) -> Sexp { } } -fn simp( - rules: &[Rule], - mut expr: Sexp, - step_limit: usize, - complexity_limit: usize, -) -> (Sexp, usize) { - let mut max = 0; - let mut grace = step_limit / 4; +fn simp(rules: &[Rule], mut expr: Sexp, step_limit: usize, complexity_limit: usize) -> Sexp { for i in 0..step_limit { expr = expr .apply_special_form::() @@ -619,24 +611,12 @@ fn simp( break; } - let last = expr.clone(); - for rule in rules { expr = rw(rule, &expr); } - - if expr == last { - grace -= 1; - } - - if grace == 0 { - break; - } - - max = i; } - (expr, max) + expr } trait SpecialForm<'src>: Sized { @@ -796,10 +776,9 @@ fn run_program(src: &str, step_limit: usize, complexity_limit: usize) -> Option< } //eprintln!("{:<50}\n{:<50}\n{:^50}", "|", "▾", expr.to_string()); - let (simped, steps) = simp(&rules, expr, step_limit, complexity_limit); + let simped = simp(&rules, expr, step_limit, complexity_limit); eprintln!("\x1b[0m"); eprintln!("Complexity: {}", simped.complexity()); - eprintln!("Steps: {}", steps + 1); Some(simped) }