remove early return when there is no change in simp
This commit is contained in:
parent
7d6aaddf81
commit
e3c75ec22b
1 changed files with 3 additions and 24 deletions
27
src/main.rs
27
src/main.rs
|
@ -3,7 +3,6 @@ use std::{
|
||||||
collections::{HashMap, HashSet},
|
collections::{HashMap, HashSet},
|
||||||
env,
|
env,
|
||||||
io::{self, Read},
|
io::{self, Read},
|
||||||
iter,
|
|
||||||
sync::Mutex,
|
sync::Mutex,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -598,14 +597,7 @@ fn rw(rule: &Rule, sexp: &Sexp) -> Sexp {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn simp(
|
fn simp(rules: &[Rule], mut expr: Sexp, step_limit: usize, complexity_limit: usize) -> Sexp {
|
||||||
rules: &[Rule],
|
|
||||||
mut expr: Sexp,
|
|
||||||
step_limit: usize,
|
|
||||||
complexity_limit: usize,
|
|
||||||
) -> (Sexp, usize) {
|
|
||||||
let mut max = 0;
|
|
||||||
let mut grace = step_limit / 4;
|
|
||||||
for i in 0..step_limit {
|
for i in 0..step_limit {
|
||||||
expr = expr
|
expr = expr
|
||||||
.apply_special_form::<Genslop>()
|
.apply_special_form::<Genslop>()
|
||||||
|
@ -619,24 +611,12 @@ fn simp(
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
let last = expr.clone();
|
|
||||||
|
|
||||||
for rule in rules {
|
for rule in rules {
|
||||||
expr = rw(rule, &expr);
|
expr = rw(rule, &expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
if expr == last {
|
|
||||||
grace -= 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if grace == 0 {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
max = i;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
(expr, max)
|
expr
|
||||||
}
|
}
|
||||||
|
|
||||||
trait SpecialForm<'src>: Sized {
|
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());
|
//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!("\x1b[0m");
|
||||||
eprintln!("Complexity: {}", simped.complexity());
|
eprintln!("Complexity: {}", simped.complexity());
|
||||||
eprintln!("Steps: {}", steps + 1);
|
|
||||||
Some(simped)
|
Some(simped)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue