Advertisement
Guest User

Untitled

a guest
Feb 20th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.34 KB | None | 0 0
  1. #|
  2. Question 4:
  3.  
  4. It would be really silly to have our compiler pass accidentally leave
  5. some NOTs or some ANDs or some ORs in the code. See if you can prove
  6. the contract for compile. As before, you don't get to assume the
  7. contract holds for be, but the induction principle will let you assume
  8. it holds for pieces of be.
  9.  
  10. Formalize in ACL2s the following statements, perform contact checking
  11. and completion and provide proofs.
  12.  
  13. 4a: Suppose (booleanp be).
  14. Prove that (cexp (compile be)).
  15.  
  16. FORMALIZATION:
  17.  
  18. (implies (booleanp be)
  19. (cexp (compile be)))
  20.  
  21. CONTRACT CHECKING AND COMPLETION:
  22.  
  23. (implies (and (booleanp be)
  24. (bexp be))
  25. (cexp (compile be)))
  26.  
  27. PROOF:
  28.  
  29. C1. (booleanp be)
  30. C2. (bexp be)
  31.  
  32. (cexp (compile be))
  33. = { Def compile, C1 }
  34. (cexp be)
  35. = { Def cexp, C1 }
  36. t
  37.  
  38.  
  39. 4b: Suppose (varp be).
  40. Prove that (cexp (compile be)).
  41.  
  42. FORMALIZATION:
  43.  
  44. (implies (varp be)
  45. (cexp (compile be)))
  46.  
  47. CONTRACT CHECKING AND COMPLETION:
  48.  
  49. (implies (and (varp be)
  50. (bexp be))
  51. (cexp (compile be)))
  52.  
  53. PROOF:
  54.  
  55. C1. (varp be)
  56. C2. (bexp be)
  57.  
  58. (cexp (compile be))
  59. = { Def compile, C1 }
  60. (cexp be)
  61. = { Def cexp, C1 }
  62. t
  63.  
  64. 4c: Suppose (bex-notp be) and
  65. (cexp (compile (second be))).
  66. Prove that (cexp (compile be)).
  67.  
  68. FORMALIZATION:
  69.  
  70. (implies (and (bex-notp be)
  71. (cexp (compile (second be))))
  72. (cexp (compile be)))
  73.  
  74. CONTRACT CHECKING AND COMPLETION:
  75.  
  76. (implies (and (bex-notp be)
  77. (cexp (compile (second be)))
  78. (bexp be))
  79. (cexp (compile be)))
  80.  
  81. PROOF:
  82.  
  83. C1. (bex-notp be)
  84. C2. (cexp (compile (second be)))
  85. C3. (bexp be)
  86.  
  87. (cexp (compile be))
  88. = { Def compile, C1 }
  89. (cexp (list 'nand
  90. (compile (second be))
  91. (compile (second be))))
  92. = { Def cexp, C2 }
  93. (cexp (list 'nand
  94. cex
  95. cex)
  96. = { Def cexp }
  97. t
  98.  
  99. 4d: Suppose (bex-andp be) and
  100. (cexp (compile (second be)))
  101. (cexp (compile (third be))).
  102. Prove that (cexp (compile be)).
  103.  
  104. FORMALIZATION:
  105.  
  106. (implies (and (bex-andp be)
  107. (cexp (compile (second be))))
  108. (cexp (compile (third be)))
  109. (cexp (compile be)))
  110.  
  111. CONTRACT CHECKING AND COMPLETION:
  112.  
  113. (implies (and (bex-andp be)
  114. (cexp (compile (second be)))
  115. (cexp (compile (third be)))
  116. (listp be)
  117. (bexp be))
  118. (cexp (compile be)))
  119.  
  120. PROOF:
  121.  
  122. C1. (bex-andp be)
  123. C2. (cexp (compile (second be)))
  124. C3. (cexp (compile (third be)))
  125. C4. (bexp be)
  126. (cexp (compile be))
  127. = { Def compile, C1 }
  128. (cexp (list 'nand
  129. (list 'nand
  130. (compile (second be))
  131. (compile (third be)))
  132. (list 'nand
  133. (compile (second be))
  134. (compile (third be)))))
  135. = { Def cexp, C2 C3 }
  136. (cexp (list 'nand
  137. (list 'nand
  138. cex
  139. cex)
  140. (list 'nand
  141. cex
  142. cex)))
  143. = { Def cexp }
  144. (cexp (list 'nand
  145. cex
  146. cex))
  147. = { Def cexp }
  148. t
  149.  
  150. 4e: Suppose (bex-orp be) and
  151. (cexp (compile (second be)))
  152. (cexp (compile (third be))).
  153. Prove that (cexp (compile be)).
  154.  
  155. FORMALIZATION:
  156.  
  157. (implies (and (bex-orp be)
  158. (cexp (compile (second be))))
  159. (cexp (compile (third be)))
  160. (cexp (compile be)))
  161.  
  162. CONTRACT CHECKING AND COMPLETION:
  163.  
  164. (implies (and (bex-orp be)
  165. (cexp (compile (second be)))
  166. (cexp (compile (third be)))
  167. (listp be)
  168. (bexp be))
  169. (cexp (compile be)))
  170.  
  171. PROOF:
  172.  
  173. C1. (bex-orp be)
  174. C2. (cexp (compile (second be)))
  175. C3. (cexp (compile (third be)))
  176. C4. (bexp be)
  177. (cexp (compile be))
  178. = { Def compile, C1 }
  179. (cexp (list 'nand
  180. (list 'nand
  181. (compile (second be))
  182. (compile (second be)))
  183. (list 'nand
  184. (compile (third be))
  185. (compile (third be)))))
  186. = { Def cexp, C2 C3 }
  187. (cexp (list 'nand
  188. (list 'nand
  189. cex
  190. cex)
  191. (list 'nand
  192. cex
  193. cex)))
  194. = { Def cexp }
  195. (cexp (list 'nand
  196. cex
  197. cex))
  198. = { Def cexp }
  199. t
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement