计算机概论-结构归纳法(structural induction)

结构归纳法(structural induction)

  • 结构归纳法(structural induction)
    • 归纳列表(induction on list)
    • 树结构的归纳

结构归纳法(structural induction)

菜鸡在ANU学习这章时发现中文资料甚少,再此进行梳理(复习)。欢迎大佬指点讨论。

归纳列表(induction on list)

如何定义列表

  1. 定义关于元素属性A的空列表[]
  2. 给出列表A的元素a,并加上前缀(写作 a:A)

如何对列表I证明特性P(I)

  1. P()对于空列表成立(p([]))
  2. 如果列表A符合P(A),对任意a证明P(a:A)成立

例:
使用以下条件
length [] = 0 (L1)
length (x:xs) = 1 + length xs (L2)
map f [] = [] (M1)
map f (x:xs) = f x : map f xs (M2)
[] ++ ys = ys (A1)
(x:xs) ++ ys = x : (xs ++ ys) (A2)
证明:∀xs.length (map f xs) = length xs.
思路:首先证明P([])成立,再证∀x.∀xs.P(xs)→P(x:xs)
解:

  1. P([ ]) length (map f [])= length []由M1推得: map f [] = []
  2. ∀x.∀xs.P(xs)→P(x:xs)
    归纳假设:对任意一个list:length (map f as) = length as
    length (map f (a:as))=
    length (f a : map f as) – by (M2)
    = 1 + length (map f as) – by (L2)
    = 1 + length as – by (IH)
    = length (a:as) – by (L2)

树结构的归纳

定义:假设任意type a

  1. Nul是树a
  2. 如果l,r是type树a,x是type a,那么结点l x r 是type树a

树的归纳假设
证明P(t)成立对于所有t属于type树a

  1. P(Nul)成立
  2. 证明只要P(l)和P(r)都为真,则P(Node l x r)成立

例:
证明count (mapT f t) = count t成立对于所有 functions f和所有树t

1.P(Nul)count (mapT f Nul) = count Nul --(M1)
2.
思路:证明count (mapT f (Node u1 a u2)) = count (Node u1 a u2)
归纳假设:对任意u1,u2,P(u1)∧P(u2) 写作:
count (mapT f u1) = count u1 – (IH1)
count (mapT f u2) = count u2 – (IH2)

count (mapT f (Node a u1 u2))
=count (Node (mapT f u1) (f x) (mapT f u2)) – by (M2)
= 1 + count (mapT f u1) + count (mapT f u2) – by (C2)
= 1 + count u1 + count u2 – by (IH1, IH2)
= count (Node a u1 u2) – by (C2)

你可能感兴趣的:(计算机理论)