레지스터는 바뀌는 값을 모두 명시한다.
기계 상태를 고정된 레지스터 값 모음으로 나타내고 한 번의 전이가 다음 상태를 계산하게 할 수 있습니다.
계산을 다시 이어 가려면 어떤 정보가 상태에 있어야 할까요?
- Represent registers as one explicit state value
- Separate a single transition from repeated execution
- Read a final state instead of only a final number
The state list holds a, b, and the number of completed transitions. step performs one Euclidean reduction and returns a new list without hiding any changing value.
run does not contain the arithmetic rule itself. It asks whether b is zero and otherwise repeats step, so the transition rule and the controller remain separate.
(begin
(define (step state)
(let ((a (car state))
(b (cadr state))
(steps (caddr state)))
(if (= b 0)
state
(list b (remainder a b) (+ steps 1)))))
(define (run state)
(if (= (cadr state) 0)
state
(run (step state))))
(run (list 206 40 0)))- 출력
- —
- 값
- —
- 진단
- —
The first program returns the final register state (2 0 4). The gcd is 2 and four transitions completed.
Follow each step application and watch the old b become the next a. The state value records the transition count alongside the arithmetic registers.
힌트를 보기 전에 프로그램을 바꿔 보세요.
Run the machine with a equal to 30 and b equal to 18. Predict the complete final state, including the transition count.
힌트 하나 보기
Write one new list after each remainder operation.