Skip to content

Commit

Permalink
Pass machine as lambda
Browse files Browse the repository at this point in the history
  • Loading branch information
nickdrozd committed Mar 9, 2024
1 parent dac21b8 commit ef8671b
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions tm/reason.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,21 @@
def cant_halt(prog: str) -> bool:
return (program := Reasoner(prog)).cant_reach(
program.halt_slots,
BackstepMachineHalt,
lambda: BackstepMachineHalt(prog),
)


def cant_blank(prog: str) -> bool:
return (program := Reasoner(prog)).cant_reach(
program.erase_slots,
BackstepMachineBlank,
lambda: BackstepMachineBlank(prog),
)


def cant_spin_out(prog: str) -> bool:
return (program := Reasoner(prog)).cant_reach(
program.spinout_slots,
BackstepMachineSpinout,
lambda: BackstepMachineSpinout(prog),
)

########################################
Expand All @@ -56,15 +56,11 @@ class Reasoner:

graph: Graph

prog_str: str

def __init__(self, program: str):
self.prog = dict(enumerate(parse(program)))

self.graph = Graph(program)

self.prog_str = program

@property
def instr_slots(self) -> list[tuple[Slot, Instr | None]]:
return [
Expand Down Expand Up @@ -99,7 +95,7 @@ def spinout_slots(self) -> tuple[Slot, ...]:
def cant_reach(
self,
slots: tuple[Slot, ...],
machine_type: Callable[[str], BackstepMachine],
get_machine: Callable[[], BackstepMachine],
max_steps: int = 24,
max_cycles: int = 1_000,
) -> bool:
Expand All @@ -113,7 +109,7 @@ def cant_reach(

seen: dict[State, set[BackstepTape]] = defaultdict(set)

machine = machine_type(self.prog_str)
machine = get_machine()

entry_points = self.graph.entry_points

Expand Down

0 comments on commit ef8671b

Please sign in to comment.