Advertisement
Guest User

Untitled

a guest
Mar 31st, 2015
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.23 KB | None | 0 0
  1. ; **************** BEGIN INITIALIZATION FOR ACL2s B MODE ****************** ;
  2. ; (Nothing to see here! Your actual file is after this initialization code);
  3.  
  4. #|
  5. Pete Manolios
  6. Fri Jan 27 09:39:00 EST 2012
  7. ----------------------------
  8.  
  9. Made changes for spring 2012.
  10.  
  11.  
  12. Pete Manolios
  13. Thu Jan 27 18:53:33 EST 2011
  14. ----------------------------
  15.  
  16. The Beginner level is the next level after Bare Bones level.
  17.  
  18. |#
  19.  
  20. ; Put CCG book first in order, since it seems this results in faster loading of this mode.
  21. #+acl2s-startup (er-progn (assign fmt-error-msg "Problem loading the CCG book.~%Please choose \"Recertify ACL2s system books\" under the ACL2s menu and retry after successful recertification.") (value :invisible))
  22. (include-book "ccg/ccg" :uncertified-okp nil :dir :acl2s-modes :ttags ((:ccg)) :load-compiled-file nil);v4.0 change
  23.  
  24. ;Common base theory for all modes.
  25. #+acl2s-startup (er-progn (assign fmt-error-msg "Problem loading ACL2s base theory book.~%Please choose \"Recertify ACL2s system books\" under the ACL2s menu and retry after successful recertification.") (value :invisible))
  26. (include-book "base-theory" :dir :acl2s-modes)
  27.  
  28. #+acl2s-startup (er-progn (assign fmt-error-msg "Problem loading ACL2s customizations book.~%Please choose \"Recertify ACL2s system books\" under the ACL2s menu and retry after successful recertification.") (value :invisible))
  29. (include-book "custom" :dir :acl2s-modes :uncertified-okp nil :ttags :all)
  30.  
  31. ;Settings common to all ACL2s modes
  32. (acl2s-common-settings)
  33.  
  34. #+acl2s-startup (er-progn (assign fmt-error-msg "Problem loading trace-star and evalable-ld-printing books.~%Please choose \"Recertify ACL2s system books\" under the ACL2s menu and retry after successful recertification.") (value :invisible))
  35. (include-book "trace-star" :uncertified-okp nil :dir :acl2s-modes :ttags ((:acl2s-interaction)) :load-compiled-file nil)
  36. (include-book "hacking/evalable-ld-printing" :uncertified-okp nil :dir :system :ttags ((:evalable-ld-printing)) :load-compiled-file nil)
  37.  
  38. #+acl2s-startup (er-progn (assign fmt-error-msg "Problem setting up ACL2s Beginner mode.") (value :invisible))
  39. ;Settings specific to ACL2s Beginner mode.
  40. (acl2s-beginner-settings)
  41.  
  42. ; why why why why
  43. (acl2::xdoc acl2s::defunc) ; almost 3 seconds
  44.  
  45. (cw "~@0Beginner mode loaded.~%~@1"
  46. #+acl2s-startup "${NoMoReSnIp}$~%" #-acl2s-startup ""
  47. #+acl2s-startup "${SnIpMeHeRe}$~%" #-acl2s-startup "")
  48.  
  49.  
  50. (acl2::in-package "ACL2S B")
  51.  
  52. ; ***************** END INITIALIZATION FOR ACL2s B MODE ******************* ;
  53. ;$ACL2s-SMode$;Beginner
  54. #|
  55.  
  56. CS 2800 Homework 9 - Spring 2015
  57.  
  58. This homework is done in groups. The rules are:
  59.  
  60. * ALL group members must submit the homework file (this file)
  61.  
  62. * the file submitted must be THE SAME for all group members (we use this
  63. to confirm that alleged group members agree to be members of that group)
  64.  
  65. * You must list the names of ALL group members below using the
  66. format below. If you fail to follow instructions, that costs
  67. us time and it will cost you points, so please read carefully.
  68.  
  69. Names of ALL group members: FirstName1 LastName1, FirstName2 LastName2, ...
  70.  
  71. There will be a 10 pt penalty if your names do not follow this format.
  72. All names must be on one line.
  73.  
  74. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  75.  
  76. For (parts of) this homework you will need to use ACL2s.
  77.  
  78. Technical instructions:
  79.  
  80. - open this file in ACL2s as hw09.lisp
  81.  
  82. - make sure you are in BEGINNER mode. This is essential! Note that you can
  83. only change the mode when the session is not running, so set the correct
  84. mode before starting the session.
  85.  
  86. - only add to the file. Do not remove or comment out anything pre-existing.
  87.  
  88. - insert your solutions into this file where indicated (usually as "...")
  89.  
  90. - make sure the entire file is accepted by ACL2s. In particular, there must
  91. be no "..." left in the code. If you don't finish all problems, comment
  92. the unfinished ones out. Comments should also be used for any English
  93. text that you may add. This file already contains many comments, so you
  94. can see what the syntax is.
  95.  
  96. - when done, save your file and submit it as hw09.lisp
  97.  
  98. - avoid submitting the session file (which shows your interaction with the
  99. theorem prover). This is not part of your solution. Only submit the lisp
  100. file.
  101.  
  102. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  103.  
  104. Instructions for programming problems:
  105.  
  106. For each function definition, you must provide both contracts and a body.
  107.  
  108. You must also ALWAYS supply your own tests. This is in addition to the
  109. tests sometimes provided. Make sure you produce sufficiently many new test
  110. cases. This means: cover at least the possible scenarios according to the
  111. data definitions of the involved types. For example, a function taking two
  112. lists should have at least 4 tests: all combinations of each list being
  113. empty and non-empty.
  114.  
  115. Beyond that, the number of tests should reflect the difficulty of the
  116. function. For very simple ones, the above coverage of the data definition
  117. cases may be sufficient. For complex functions with numerical output, you
  118. want to test whether it produces the correct output on a reasonable
  119. number if inputs.
  120.  
  121. Use good judgment. For unreasonably few test cases we will deduct points.
  122.  
  123. We will use ACL2s' check= function for tests. This is a two-argument
  124. function that rejects two inputs that do not evaluate equal. You can think
  125. of check= roughly as defined like this:
  126.  
  127. (defunc check= (x y)
  128. :input-contract (equal x y)
  129. :output-contract (equal (check= x y) t)
  130. t)
  131.  
  132. That is, check= only accepts two inputs with equal value. For such inputs, t
  133. (or "pass") is returned. For other inputs, you get an error. If any check=
  134. test in your file does not pass, your file will be rejected.
  135.  
  136. |#
  137.  
  138. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  139. ; Induction schemes
  140. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  141.  
  142.  
  143. #|
  144.  
  145. Below you are given the proof obligations generated by
  146. induction schemes. Your job is to define functions, using defunc
  147. that give rise to these induction schemes. phi|(...) denotes phi
  148. under substitution ... . Make sure that ACL2s accepts your
  149. function definitions.
  150.  
  151. For these functions (f1-f5) you do not need to provide
  152. tests (i.e., no check= forms are required).
  153.  
  154. |#
  155.  
  156.  
  157. #|
  158.  
  159. 1. (not (natp x)) => phi
  160. 2. (and (natp x) (equal x 0)) => phi
  161. 3. (and (natp x) (not (equal x 0)) phi|((x (- x 1)))) => phi
  162.  
  163. |#
  164.  
  165. (defunc f1 (x)
  166. :input-contract (natp x)
  167. :output-contract (natp (f1 x))
  168. (if (equal x 0)
  169. 0
  170. (f1 (- x 1))))
  171.  
  172. #|
  173.  
  174. 1. (not (posp x)) => phi
  175. 2. (and (posp x) (equal x 1)) => phi
  176. 3. (and (posp x) (equal x 2)) => phi
  177. 4. (and (posp x) (not (equal x 1)) (not (equal x 2)) phi|((x (- x 2)))) => phi
  178.  
  179. |#
  180.  
  181. (defunc f2 (x)
  182. :input-contract (posp x)
  183. :output-contract (posp (f2 x))
  184. (cond ((equal x 1) 1)
  185. ((equal x 2) 2)
  186. (t (f2 (- x 2)))))
  187.  
  188. #|
  189.  
  190. 1. (not (listp x)) => phi
  191. 2. (and (listp x) (endp x)) => phi
  192. 3. (and (listp x) (not (endp x)) phi|((x (rest x)))) => phi
  193.  
  194. |#
  195.  
  196. (defunc f3 (x)
  197. :input-contract (listp x)
  198. :output-contract (natp (f3 x))
  199. (if (endp x)
  200. 0
  201. (+ 1 (f3 (rest x)))))
  202.  
  203. #|
  204.  
  205. 1. (not (listp x)) => phi
  206. 2. (and (listp x) (endp x)) => phi
  207. 3. (and (listp x) (not (endp x)) (endp (rest x))) => phi
  208. 4. (and (listp x) (not (endp x)) (not (endp (rest x)))
  209. phi|((x (rest x))) phi|((x (rest (rest x))))) => phi
  210.  
  211. |#
  212.  
  213. (defunc f4 (x)
  214. :input-contract (listp x)
  215. :output-contract (natp (f4 x))
  216. (cond ((endp x) 0)
  217. ((endp (rest x)) 1)
  218. (t (+ (f4 (rest x)) (f4 (rest (rest x)))))))
  219.  
  220. #|
  221.  
  222. 1. (not (and (listp x) (posp y))) => phi
  223. 2. (and (listp x) (posp y) (endp x) (equal y 1)) => phi
  224. 3. (and (listp x) (posp y) (not (and (endp x) (equal y 1)))
  225. (endp x) phi|((y (- y 1))) phi|((x (cons 1 x)) (y (- y 1)))) => phi
  226. 4. (and (listp x) (posp y) (not (and (endp x) (equal y 1)))
  227. (not (endp x)) (equal y 1) phi|((x (rest x))) => phi
  228. 5. (and (listp x) (posp y) (not (and (endp x) (equal y 1)))
  229. (not (endp x)) (not (equal y 1)) phi|((x (rest x)))
  230. phi|((y (- y 1)))) => phi
  231.  
  232. Hint: phi|((a (rest a)) (b b)) is the same as
  233. phi|((a (rest a)))
  234. |#
  235.  
  236.  
  237. #|
  238. f5 timed out
  239.  
  240. (defunc f5 (x y)
  241. :input-contract (and (listp x) (posp y))
  242. :output-contract (natp (f5 x y))
  243. (cond ((and (endp x) (equal y 1)) y)
  244. ((endp x) (+ (f5 x (- y 1)) (f5 (cons 1 x) (- y 1))))
  245. ((equal y 1) (f5 (rest x) y))
  246. (t (+ (f5 (rest x) y) (f5 x (- y 1))))))
  247. |#
  248.  
  249.  
  250. #|
  251.  
  252. We start with some familiar definitions. You will be asked to
  253. define functions later on. Make sure to use defunc.
  254.  
  255. (defunc listp (x)
  256. :input-contract t
  257. :output-contract (booleanp (listp x))
  258. (if (consp x)
  259. (listp (rest x))
  260. (equal x nil)))
  261.  
  262. (defunc app (a b)
  263. :input-contract (and (listp a) (listp b))
  264. :output-contract (listp (app a b))
  265. (if (endp a)
  266. b
  267. (cons (first a) (app (rest a) b))))
  268.  
  269. (defunc rev (a)
  270. :input-contract (listp a)
  271. :output-contract (listp (rev a))
  272. (if (endp a)
  273. nil
  274. (app (rev (rest a)) (list (first a)))))
  275.  
  276. (defunc len (a)
  277. :input-contract t
  278. :output-contract (natp (len a))
  279. (if (atom a)
  280. 0
  281. (+ 1 (len (rest a)))))
  282.  
  283. (defunc in (a X)
  284. :input-contract (listp x)
  285. :output-contract (booleanp (in a X))
  286. (if (endp x)
  287. nil
  288. (or (equal a (first X))
  289. (in a (rest X)))))
  290.  
  291. |#
  292.  
  293.  
  294. #|
  295.  
  296. Use defdata to define a lor, a list of rational numbers.
  297.  
  298. |#
  299.  
  300. (defdata lor (listof rational))
  301.  
  302. #|
  303.  
  304. Define orderedp: a function that given a lorp returns a
  305. boolean. orderedp check to see if the list of rationals is
  306. ordered, ie, if each element is <= the elements that come after it.
  307.  
  308. |#
  309.  
  310. (defunc orderedp (l)
  311. :input-contract (lorp l)
  312. :output-contract (booleanp (orderedp l))
  313. (cond ((endp l) t)
  314. ((endp (rest l)) t)
  315. (t (and (<= (first l) (second l))
  316. (orderedp (rest l))))))
  317.  
  318. (check= (orderedp '()) t)
  319. (check= (orderedp '(4)) t)
  320. (check= (orderedp '(0 4 2)) nil)
  321. (check= (orderedp '(0 3 5 6)) t)
  322. (check= (orderedp '(1 0)) nil)
  323.  
  324.  
  325. #|
  326.  
  327. Define insert, a function that is given as input e and l. e
  328. is a rational number and l is a lorp. Insert traverses l until
  329. it finds a number >= e and inserts e right before this number.
  330. For example (insert 3 '(2 5 6)) is '(2 3 5 6)
  331. |#
  332.  
  333. (defunc insert (e l)
  334. :input-contract (and (lorp l) (rationalp e))
  335. :output-contract (lorp (insert e l))
  336. (cond ((endp l) (list e))
  337. ((>= (first l) e) (cons e l))
  338. (t (cons (first l) (insert e (rest l))))))
  339.  
  340. (check= (insert 3 '()) '(3))
  341. (check= (insert 3 '(1 2)) '(1 2 3))
  342. (check= (insert 3 '(1 4 5)) '(1 3 4 5))
  343. (check= (insert 3 '(4 5)) '(3 4 5))
  344.  
  345. #|
  346.  
  347. Formalize and prove (by hand) the following conjecture:
  348.  
  349. (insert e l) returns a list whose length is 1 more than the
  350. length of l.
  351.  
  352. For this and all subsequent questions where you are asked to
  353. prove a theorem by hand, use the proof format introduced in class
  354. and write your answer in a comment. If you are using induction,
  355. clearly identify the function you are using to generate an
  356. induction scheme.
  357.  
  358. |#
  359.  
  360. #|
  361.  
  362. T1:
  363. (implies (and (listp l)
  364. (rationalp e))
  365. (equal (+ 1 (len l))
  366. (len (insert e l))))
  367.  
  368. Proof:
  369. This function's induction scheme is
  370.  
  371. 1. ~(and (listp l) (rationalp e)) => phi
  372. 2. (and (listp l) (rationalp e) (endp l)) => phi
  373. 3. (and (listp l) (rationalp e) ~(endp l) (e < (first l)) (phi | (l (rest l))))
  374. 3. (and (listp l) (rationalp e) ~(endp l) (e > (first l)) (phi | (l (rest l))))
  375.  
  376. obligation 1:
  377.  
  378. c1: (listp l)
  379. c1: (rationalp e)
  380.  
  381. ~(and (listp l) (rationalp e)) => phi
  382.  
  383. ={c1, c2}
  384. nil => phi
  385.  
  386. ={implies}
  387. t
  388.  
  389. obligation 2:
  390.  
  391. c1: (listp l)
  392. c2: (rationalp e)
  393. c3: (endp l)
  394.  
  395. (and (listp l) (rationalp e) (endp l)) => phi
  396.  
  397.  
  398. ={c1, c2, c3, def phi}
  399. (equal (+ 1 (len l))
  400. (len (insert e l)))
  401.  
  402. ={def insert, c2, c3}
  403. (equal (+ 1 (len (nil)))
  404. (len (list e)))
  405.  
  406. ={def len, c3}
  407. (equal (+ 1 0)
  408. (1))
  409.  
  410. ={arith, def equal}
  411. t
  412.  
  413. obligation 3:
  414. c1: (listp l)
  415. c2: (rationalp e)
  416. c3: ~(endp l)
  417. c4. e < (first l)
  418. c5: (phi | (l (rest l)))
  419.  
  420.  
  421. derived context
  422. ={c1,c2,c3,c4,c5}
  423. c6: (equal (+ 1 (len (rest l)))
  424. (len (insert e (rest l))))
  425.  
  426. ={def insert, c1, c2, c3, c4}
  427. (equal (+ 1 (len (rest l)))
  428. (len (cons e (rest l))))
  429.  
  430. ={def len}
  431. (equal (+ 1 (len (rest l)))
  432. (+ 1 (len (rest l))))
  433.  
  434. ={arith, equal}
  435. t
  436.  
  437. obligation 4:
  438.  
  439. c1: (listp l)
  440. c2: (rationalp e)
  441. c3: ~(endp l)
  442. c4. e > (first l)
  443. c5: (phi | (l (rest l)))
  444.  
  445.  
  446. derived context
  447. ={c1,c2,c3,c4,c5}
  448. c6: (equal (+ 1 (len (rest l)))
  449. (len (insert e (rest l))))
  450.  
  451. ={def insert, c1, c2, c3, c4}
  452. (equal (+ 1 (len (rest l)))
  453. (len (cons (first (rest l) (insert e ((rest (rest l))))))))
  454.  
  455. ={def len, c1, c2, c3}
  456. (equal (+ 1 (len (rest l)))
  457. (+ 1 (len (insert e ((rest (rest l))))))))
  458.  
  459.  
  460. 1. ~(and (listp l) (rationalp e)) => phi
  461. 2. (and (listp l) (rationalp e) (endp l)) => phi
  462. 3. (and (listp l) (rationalp e) ~(endp l) (e < (first l)) (phi | (l (rest l))))
  463. 3. (and (listp l) (rationalp e) ~(endp l) (e > (first l)) (phi | (l (rest l))))
  464.  
  465. given the above, phi is valid for all l and e
  466. |#
  467.  
  468. #|
  469.  
  470. Define isort, a function that is given as input a lorp, and
  471. sorts using insertion sort: if l is empty, return nil. If not,
  472. insert the first into the result of sorting the rest.
  473.  
  474. |#
  475.  
  476. (defunc isort (l)
  477. :input-contract (lorp l)
  478. :output-contract (lorp (isort l))
  479. (cond ((endp l) l)
  480. (t (insert (first l)
  481. (isort (rest l))))))
  482.  
  483. (check= (isort '()) '())
  484. (check= (isort '(0)) '(0))
  485. (check= (isort '(1 2)) '(1 2))
  486. (check= (isort '(2 1)) '(1 2))
  487. (check= (isort '(2 84 0 -9 3)) '(-9 0 2 3 84))
  488.  
  489.  
  490. #|
  491.  
  492. Formalize and prove (by hand) the following conjecture:
  493.  
  494. (isort l) returns a list whose length is equal to the length of l.
  495.  
  496. Use the proof format introduced in class and write your answer in
  497. this comment.
  498.  
  499. |#
  500.  
  501. #|
  502.  
  503. Here is the formalization:
  504.  
  505. (implies (lorp l)
  506. (equal (len (isort l))
  507. (len l))))
  508.  
  509. Here is the proof:
  510.  
  511. proof obligations:
  512.  
  513. 1. ~(lorp l) => phi
  514. 2. (and (lorp l) (endp l)) => phi
  515. 3. (and (lorp l) ~(endp l) (phi | (l (rest l)))) => phi
  516.  
  517. 1.
  518.  
  519. c1. (lorp l)
  520. ~(lorp l) => phi
  521.  
  522. ={c1}
  523. nil => phi
  524.  
  525. ={implies}
  526. t
  527.  
  528. 2.
  529.  
  530. c1. (lorp l)
  531. c2. (endp l)
  532.  
  533. (and (lorp l) (endp l)) => (equal (len (isort l))
  534. (len l))
  535.  
  536. ={c1, c2}
  537. (equal (len (isort l)) (len l))
  538.  
  539. ={c2, def isort, def len, arith}
  540. 0
  541.  
  542. 3.
  543.  
  544. c1. (lorp l)
  545. c2. ~(endp l)
  546. c3. (phi | (l (rest l)))
  547.  
  548. ={c1,c2}
  549. c4. (consp l)
  550.  
  551. ={c3, phi}
  552. c5. (equal (len (isort (rest l)))
  553. (len (rest l)))
  554.  
  555. (equal (len (isort l))
  556. (len l)))
  557.  
  558. ={def isort, c2}
  559. (equal (len (insert (first l)
  560. (isort (rest l))))
  561. (len l)))
  562.  
  563. ={def len, c4, T1}
  564. (equal (+ 1 (len (isort (rest l))))
  565. (+ 1 (len (rest l))))
  566.  
  567. ={arith, c5}
  568. t
  569.  
  570. given the above, phi is valid for all l
  571.  
  572. |#
  573.  
  574. #|
  575.  
  576. Formalize and prove (by hand) the following conjecture:
  577.  
  578. If l is a lorp, then (isort l) is ordered (satisfies orderedp).
  579.  
  580. Use the proof format introduced in class and write your answer in
  581. this comment.
  582.  
  583. Hint: You will need a lemma.
  584.  
  585. Warning: This proof is not hard, but you will have to discover
  586. and prove a lemma, so the proof will be long. Give yourself
  587. plenty of time to complete this problem. Coming up with the lemma
  588. is going to require some insight!
  589.  
  590. |#
  591.  
  592.  
  593.  
  594. #|
  595.  
  596. Here is the formalization:
  597.  
  598. (implies (lorp l)
  599. (orderedp (isort l)))
  600.  
  601.  
  602. Here is the proof:
  603.  
  604.  
  605. proof lemma:
  606.  
  607. (implies (and (rationalp e) (lorp l) (orderedp l))
  608. (orderedp (insert e l)))
  609.  
  610. proof contract:
  611. 1. ~(and (lorp l) (rationalp e)) => phi
  612. 2. (and (lorp l) (rationalp e) (endp l)) => phi
  613. 3. (and (lorp l) (rationalp e) ~(endp l) (>= (first l) e)) => phi
  614. 4. (and (lorp l) (rationalp e) ~(endp l) ~(>= (first l) e) (phi | (l (rest l)))) => phi
  615.  
  616.  
  617. obligation 1:
  618.  
  619. c1. (lorp l)
  620.  
  621. proof:
  622. ~(and (lorp l) (rationalp e)) => phi
  623.  
  624. ={c1, implies}
  625. t
  626.  
  627. obligation 2:
  628.  
  629. c1. (lorp l)
  630. c2. (rationalp e)
  631. c3. (endp l)
  632.  
  633. proof:
  634.  
  635. (orderedp (insert e l))
  636.  
  637. ={def insert, c3}
  638. (orderedp (list e))
  639.  
  640. ={def orderedp}
  641. t
  642.  
  643. obligation 3:
  644.  
  645. c1. (lorp l)
  646. c2. (rationalp e)
  647. c3. ~(endp l)
  648. c4. (>= (first l) e))
  649. c5. (orderedp l)
  650.  
  651. proof:
  652. (orderedp (insert e l))
  653.  
  654. ={def insert, c3, c4}
  655. (ordered (cons e l))
  656.  
  657. ={def orderedp, c4}
  658. (and (<= e (first l))
  659. (orderedp (rest (cons e l))))
  660.  
  661. ={arith, def rest}
  662. (and t
  663. (orderedp l))
  664.  
  665. ={c5}
  666. t
  667.  
  668. obligation 4:
  669.  
  670. c1. (lorp l)
  671. c2. (rationalp e)
  672. c3. ~(endp l)
  673. c4. ~(>= (first l) e))
  674. c5. (orderedp l)
  675. c6. (phi | (l | (rest l)))
  676.  
  677. ={c5, phi}
  678. c6.(orderedp (insert e (rest l)))
  679.  
  680. proof:
  681. (orderedp (insert e l))
  682.  
  683. ={def insert, c3, c4}
  684. (orderedp (cons (first l) (insert e (rest l))))
  685.  
  686. ={def orderedp, c3, def cons}
  687. (and (<= (first l) (first (insert e (rest l))))
  688. (orderedp (insert e (rest l))))
  689.  
  690. ={c6, boolean logic}
  691. (<= (first l) (first (insert e (rest l))))
  692.  
  693. ={c5, c4}
  694. t
  695.  
  696. due to the above,
  697. (implies (and (rationalp e) (lorp l) (orderedp l))
  698. (orderedp (insert e l)))
  699.  
  700.  
  701. proof Theorem:
  702. (implies (lorp l)
  703. (orderedp (isort l)))
  704.  
  705. proof obligations:
  706. 1. ~(lorp l) => phi
  707. 2. (and (lorp l) (endp l)) => phi
  708. 3. (and (lorp l) ~(endp l) (phi | (l (rest l)))) => phi
  709.  
  710. obligation 1:
  711.  
  712. c1: (lorp l)
  713.  
  714. (lorp l) => phi
  715.  
  716. ={c1}
  717. t
  718.  
  719. obligation 2:
  720. c1: (lorp l)
  721. c2: (endp l)
  722.  
  723. (orderedp (isort l))
  724.  
  725. ={def isort, c2}
  726. (orderedp '())
  727.  
  728. ={def orderedp}
  729. t
  730.  
  731. obligation 3:
  732. c1: (lorp l)
  733. c2: ~(endp l)
  734. c3: (phi | (l (rest l)))
  735.  
  736. ={c3, phi, c2}
  737. c4: (orderedp (isort (rest l)))
  738.  
  739.  
  740. (orderedp (isort l))
  741.  
  742. ={def isort, c2}
  743. (orderedp (insert (first l)
  744. (isort (rest l))))
  745.  
  746. ={(lemma | (e (first l)) (l (rest l)), c4,c2,c3,c1}
  747. t
  748.  
  749. due to the above, (implies (lorp l) (orderedp (isort l)))
  750.  
  751. |#
  752.  
  753.  
  754. #|
  755.  
  756. Extra credit.
  757.  
  758. Get ACL2s to prove all of the theorems you were asked to prove by
  759. hand, including the lemma you had to discover. Here is how you
  760. do that.
  761.  
  762. Suppose that the theorem you want to prove is
  763.  
  764. (listp x) => (app x nil) = x
  765.  
  766. First, turn it into a legal ACL2s expression and second use
  767. the "defthm" form, which requires giving the theorem a name. Here
  768. is what the defthm will look like:
  769.  
  770. (defthm app-x-nil-thm
  771. (implies (listp x)
  772. (equal (app x nil)
  773. x)))
  774.  
  775. One thing to keep in mind is that if you have a defthm of
  776. the form
  777.  
  778. (1) hyp1 /\ hyp2 /\ ... /\ hypn => (f ...) = (g ...)
  779.  
  780. then you could write it as
  781.  
  782. (2) hyp1 /\ hyp2 /\ ... /\ hypn => (g ...) = (f ...)
  783.  
  784. Logically there is no difference, but in ACL2s there is a big
  785. difference. Put the more "complicated" of (g ...) and (f ...) on
  786. the left of the equality because ACL2s uses the defthms as what
  787. are called rewrite rules, i.e., if you defthm is of form (1) then
  788. ACL2s replaces (f ...) by (g ...) but not the other way around.
  789.  
  790. Another minor issue: replace every occurrence of the function len with
  791. acl2::len, so instead of (len x) write (acl2::len x).
  792.  
  793. Finally place the defthms in the same order as you were asked to
  794. prove them and lemmas that were used in the proof of a theorem
  795. should come before the theorem.
  796.  
  797. If you do it right, this should be easy. Also, you should try
  798. this even if you didn't do all the proofs.
  799.  
  800. |#
  801.  
  802. (defthm T1
  803. (implies (and (rationalp e) (lorp l))
  804. (equal (+ 1 (acl2::len l))
  805. (acl2::len (insert e l)))))
  806.  
  807.  
  808. (defthm lemma1
  809. (implies (and (rationalp e) (lorp l) (orderedp l))
  810. (orderedp (insert e l))))
  811.  
  812. (defthm T3
  813. (implies (lorp l)
  814. (orderedp (isort l))))
  815.  
  816.  
  817. "this is the second theorem. It doesn't finish evaluating, but we believe it to be correct"
  818. #|ACL2s-ToDo-Line|#
  819. (defthm T2
  820. (implies (lorp l)
  821. (equal (acl2::len (isort l))
  822. (acl2::len l))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement