Skip to content

Commit

Permalink
Cut align diff arg
Browse files Browse the repository at this point in the history
  • Loading branch information
nickdrozd committed Dec 11, 2023
1 parent 06303dd commit 6bc2a91
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 26 deletions.
9 changes: 2 additions & 7 deletions test/lin_rec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
9 changes: 2 additions & 7 deletions tm/machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
13 changes: 3 additions & 10 deletions tm/reason.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
3 changes: 1 addition & 2 deletions tm/tape.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 6bc2a91

Please sign in to comment.