图灵机相关知识详解
1. 非确定性图灵机
1.1 不变谓词的实现
在非确定性图灵机中,有一些重要的不变谓词需要实现。例如,对于 Y - INV 和 N - INV 有如下代码实现及测试:
(check-equal? (Y-INV `(,LM a a a) 1) #f)
(check-equal? (Y-INV `(,LM b a a) 3) #f)
(check-equal? (Y-INV `(,LM a a a a ,BLANK) 5) #t)
(check-equal? (Y-INV `(,LM a a a a a b,BLANK) 7) #t)
;; tape natnum →Boolean
;; Purpose: Determine that tape[1..i-1] != a* or a*b
(define (N-INV t i)
(and (not (andmap (λ (s) (eq? s 'a))
(take (rest t) (sub1 i))))
(let* [(front (takef (rest t) (λ (s) (eq? s 'a))))
(back (takef (drop t (add1 (length front)))
(λ (s) (not (eq? s BLANK)))))]
(not (equal? back '(b))))))
(check-equal?
超级会员免费看
订阅专栏 解锁全文
267

被折叠的 条评论
为什么被折叠?



