diff --git a/test/lin_rec.py b/test/lin_rec.py index ae810d85..98ccc619 100644 --- a/test/lin_rec.py +++ b/test/lin_rec.py @@ -374,7 +374,7 @@ def run(self, sim_lim: int) -> Self: # no-cover while cycle < sim_lim: steps_reset = 2 * step - leftmost = rightmost = init_pos = tape.head + leftmost = rightmost = tape.head init_state = state @@ -423,12 +423,7 @@ def run(self, sim_lim: int) -> Self: # no-cover if tape.scan != init_tape.scan: continue - if tape.aligns_with( - init_tape, - curr - init_pos, - leftmost, - rightmost, - ): + if tape.aligns_with(init_tape, leftmost, rightmost): self.infrul = step break diff --git a/tm/machine.py b/tm/machine.py index 8d5edf17..56dbbf27 100644 --- a/tm/machine.py +++ b/tm/machine.py @@ -274,7 +274,7 @@ def quick_term_or_rec(prog: str, sim_lim: int) -> bool: while cycle < sim_lim: steps_reset = 2 * step - leftmost = rightmost = init_pos = tape.head + leftmost = rightmost = tape.head init_state = state @@ -309,12 +309,7 @@ def quick_term_or_rec(prog: str, sim_lim: int) -> bool: if tape.scan != init_tape.scan: continue - if tape.aligns_with( - init_tape, - curr - init_pos, - leftmost, - rightmost, - ): + if tape.aligns_with(init_tape, leftmost, rightmost): return True return False diff --git a/tm/reason.py b/tm/reason.py index 931aeda6..853e7d78 100644 --- a/tm/reason.py +++ b/tm/reason.py @@ -287,8 +287,7 @@ def __iter__(self) -> Iterator[History]: prev = prev.prev def check_rec(self) -> bool: - curr_head = self.head - assert curr_head is not None + assert (curr_head := self.head) is not None leftmost = rightmost = curr_head @@ -299,8 +298,7 @@ def check_rec(self) -> bool: if self.state != prev.state or self.scan != prev.scan: continue - prev_head = prev.head - assert prev_head is not None + assert (prev_head := prev.head) is not None if prev_head < leftmost: leftmost = prev_head @@ -310,12 +308,7 @@ def check_rec(self) -> bool: prev_tape = prev.tape assert prev_tape is not None - if curr_tape.aligns_with( - prev_tape, - curr_head - prev_head, - leftmost, - rightmost, - ): + if curr_tape.aligns_with(prev_tape, leftmost, rightmost): return True return False diff --git a/tm/tape.py b/tm/tape.py index a79c7aa0..92ff7c0f 100644 --- a/tm/tape.py +++ b/tm/tape.py @@ -678,11 +678,10 @@ def get_cnt(self, start: int, stop: int) -> TapeSlice: def aligns_with( self, prev: HeadTape, - diff: int, leftmost: int, rightmost: int, ) -> bool: - if 0 < diff: + if 0 < (diff := self.head - prev.head): slice1 = prev.get_ltr(leftmost) slice2 = self.get_ltr(leftmost + diff)