概述
/***********************问题一****************************/
问题 证明 returnM 10 :|-- (fn v => returnM (v+20))=returnM 30
解:前提
fun returnM v =fun s => (v,s) 条件<1>
fun m :|-- mf = fun s =>let
val (v1,s1) = m s
val m' = mf v1
val (v2,s2) = m' s1
in
(v2,s2)
end 条件<2>
returnM 10 :|-- (fn v => returnM (v+20))
=>使用条件<2>
= fun s => let
val (v1,s1) = m s
val m' = mf v1
val (v2,s2) = m' s1
in
(v2,s2)
end
其中m=returnM 10
mf=fn v => returnM (v+20)
=>将m=returnM 10代入式中
= fun s => let
val (v1,s1) = returnM 10 s
val m' = mf v1
val (v2,s2) = m' s1
in
(v2,s2)
end
其中mf=fn v => returnM (v+20)
=>使用条件<1>
= fun s => let
val (v1,s1) = (10,s)
val m' = mf v1
val (v2,s2) = m' s1
in
(v2,s2)
end
其中mf=fn v => returnM (v+20)
=>所以 v1=10,s1=s 。 化简后
= fun s => let
val m' = mf 10
val (v2,s2) = m' s
in
(v2,s2)
end
其中mf=fn v => returnM (v+20)
=>将mf=fn v => returnM (v+20)带入式中
= fun s => let
val m' = (fn v => returnM (v+20))10
val (v2,s2) = m' s
in
(v2,s2)
end
=>经化简
= fun s => let
val m' = returnM 30
val (v2,s2) = m' s
in
(v2,s2)
end
=>经化简
= fun s => let
val (v2,s2) = returnM 30 s
in
(v2,s2)
end
=>经化简
= fun s => let
val (v2,s2) = returnM 30 s
in
(v2,s2)
end
=>因为 (v2,s2) = returnM 30 s,将 returnM 30 s 把 (v2,s2) 替换
= fun s => let
val (v2,s2) = returnM 30 s
in
returnM 30 s
end
=>经化简
= fun s => returnM 30 s
= returnM 30
/***********************问题二****************************/
问题 证明 m>>f 的通用实现与直接实现等价
解:前提
fun returnM v =fun s => (v,s) 条件<1>
fun m :|-- mf = fun s =>let
val (v1,s1) = m s
val m' = mf v1
val (v2,s2) = m' s1
in
(v2,s2)
end 条件<2>
已知
fun m>>f =fun s => let
val (v1,s1) = m s 条件<3>
val v2 = f v1 条件<4>
val m' = returnM v2 条件<5>
val (v3,s3) = m' s1 条件<6>
in
(v3,s3)
end 条件<>
证明
fun m>>f = m :|-- (fun v => returnM f v)
=>将条件<2>带入式中
= fun s => let
val (v1',s1') = m s
val m" = mf v1'
val (v2',s2') = m" s1'
in
(v2',s2')
end
其中 mf=(fun v => returnM f v)
=>将条件<3>带入式中 (v1,s1) = m s=(v1',s1')
= fun s => let
val (v1,s1) = m s
val m"= mf v1
val (v2',s2') = m" s1
in
(v2',s2')
end
=>经化简,并将mf=(fun v => returnM f v) 带入式中
= fun s => let
val m" = (fun v => returnM f v) v1
val (v2',s2') = m" s1
in
(v2',s2')
end
=>经化简
= fun s => let
val m" = returnM f v1
val (v2',s2') = m" s1
in
(v2',s2')
end
=>带入条件<4> v2 = f v1
= fun s => let
val m" = returnM v2
val (v2',s2') = m" s1
in
(v2',s2')
end
=>带入条件<5>m' = returnM v2
= fun s => let
val m" = m'
val (v2',s2') = m" s1
in
(v2',s2')
end
=>经化简
= fun s => let
val (v2',s2') = m' s1
in
(v2',s2')
end
=>带入条件<6>(v3,s3) = m' s1
= fun s => let
val (v2',s2') = (v3,s3)
in
(v2',s2')
end
=>经化简
= fun s => (v3,s3)
所以 m>>f 的通用实现与直接实现等价
最后
以上就是活泼大侠为你收集整理的ML函数式程序设计 之 单体证明的全部内容,希望文章能够帮你解决ML函数式程序设计 之 单体证明所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复