other
(in-package "STD")
other
(include-book "../define")
other
(include-book "utils")
other
(include-book "std/testing/assert-bang" :dir :system)
other
(include-book "std/testing/must-fail" :dir :system)
other
(define foo nil :returns (ans integerp) 3)
other
(assert-disabled foo)
other
(assert-guard-verified foo)
other
(assert-enabled foo2)
other
(assert-guard-verified foo2)
other
(define foo3 nil (mv 3 "hi"))
other
(define foo4 nil :returns (ans integerp) 44)
other
(define foo5 ((x oddp :type integer)) :returns (ans integerp :hyp :guard) (- x 1))
other
(assert-guard-verified foo5)
other
(define foo7
:parents (|look ma, parents before formals, even!|)
(x)
(consp x))
other
(assert-guard-verified foo7)
other
(encapsulate nil (logic) (define foo8 (x) :mode :program (+ 1 x)))
other
(encapsulate nil (logic) (define foo9 (x) (declare (xargs :mode :program)) (+ 2 x)))
other
(encapsulate nil (program) (define foo10 ((x natp)) (declare (xargs :mode :logic)) (+ 2 x)) (assert-guard-verified foo10))
other
(encapsulate nil (program) (define foo11 (x) (declare (xargs :mode :program)) (+ 3 x)))
other
(encapsulate nil (program) (define foo12 (x) :mode :program (+ 3 x)))
other
(encapsulate nil (logic) (define bar8 (x &optional y) :mode :program (+ 1 x y)))
other
(encapsulate nil (logic) (define bar9 (x &optional y) (declare (xargs :mode :program)) (+ 2 x y)))
other
(encapsulate nil (program) (define bar10 ((x natp) &optional (y natp)) (declare (xargs :mode :logic)) (+ 2 x y)))
other
(encapsulate nil (program) (define bar11 (x &optional y) (declare (xargs :mode :program)) (+ 3 x y)))
other
(encapsulate nil (program) (define bar12 (x &optional y) :mode :program (+ 3 x y)))
other
(define m0 (x) (consp x))
other
(assert-guard-verified m0)
other
(set-default-parents foo bar)
other
(define m1 (x) (consp x))
other
(assert! (let ((topic (find-topic 'm1
(get-xdoc-table (w state)))))
(and topic
(equal (cdr (assoc :parents topic))
'(foo bar)))))
other
(define m2
(x)
(consp x)
:parents (bar))
other
(assert! (let ((topic (find-topic 'm2
(get-xdoc-table (w state)))))
(and topic
(equal (cdr (assoc :parents topic)) '(bar)))))
other
(define m3 (x) (consp x) :parents nil)
other
(defsection foo :short "foo bar")
other
(define check0 (x) :non-executable t :returns (mv (a natp) (b natp)) (mv (nfix x) (1+ (nfix x))))
other
(define check1 (x) :non-executable t :returns (mv (a natp) (b natp)) :short "testing" (mv (nfix x) (1+ (nfix x))))
other
(define check2 (x) :non-executable t :returns (mv (a natp) (b natp)) :short "testing" (mv (nfix x) (1+ (nfix x))))
other
(define frags (x) (if (atom x) 1 (+ 1 (frags (cdr x)))) /// "<p>This would be better written as a type-prescription rule:</p>" (defthm posp-of-frags (posp (frags x))) "<p>But this would not make a good type prescription rule:</p>" (defthm frags-of-cons (equal (frags (cons a x)) (+ 1 (frags x)))))
other
(assert-guard-verified frags)
other
(define test-shortcat (x) :short (concatenate 'string "Test of evaluation of " "short strings for define.") x)
other
(assert! (stringp (cdr (assoc :short (find-topic 'test-shortcat (get-xdoc-table (w state)))))))
other
(define test-longcat (x) :long (concatenate 'string "Test of evaluation of " "long strings for define.") x)
other
(define mathstuff ((a natp) (b natp)) :returns (mv (sum natp :rule-classes :type-prescription) (prod natp :rule-classes :type-prescription)) :ret-patbinder t (b* ((a (nfix a)) (b (nfix b))) (mv (+ a b) (* a b))))
other
(assert-guard-verified mathstuff)
other
(define do-math-stuff ((a natp) (b natp)) (b* ((a (nfix a)) (b (nfix b)) ((ret stuff) (mathstuff a b))) (list :sum stuff.sum :prod stuff.prod)) /// (assert! (equal (do-math-stuff 1 2) (list :sum 3 :prod 2))))
other
(make-define-config :ret-patbinder t)
other
(define mathstuff2 ((a natp) (b natp)) :returns (mv (sum natp :rule-classes :type-prescription) (prod natp :rule-classes :type-prescription)) (b* ((a (nfix a)) (b (nfix b))) (mv (+ a b) (* a b))))
other
(define do-math-stuff2 ((a natp) (b natp)) (b* ((a (nfix a)) (b (nfix b)) ((ret stuff) (mathstuff2 a b))) (list :sum stuff.sum :prod stuff.prod)) /// (assert! (equal (do-math-stuff2 1 2) (list :sum 3 :prod 2))))
other
(defstobj foost (foo-x))
other
(defstobj barst (bar-x) :congruent-to foost)
other
(define modify-foo
(x &key (foost 'foost))
:returns (foo-out)
(update-foo-x x foost))
other
(define use-bar
(x barst)
(b* (((ret) (modify-foo x :foost barst)))
barst))
other
(must-fail (define rva-1
(x)
:returns (mv a b)
x))
other
(must-fail (define rva-2
(x)
:returns ans
(mv x x)))
other
(must-fail (define rva-3
(x state)
:returns state
(mv x state)))
other
(must-fail (define rvap-1
(x)
:returns (mv a b)
:mode :program x))
other
(must-fail (define rvap-2
(x)
:returns ans
:mode :program (mv x x)))
other
(must-fail (define rvap-3
(x state)
:returns state
:mode :program (mv x state)))
my-hookfunction
(defun my-hook (guts opts state) (declare (xargs :mode :program :stobjs state)) (declare (ignore guts opts)) (value '(value-triple :invisible)))
my-hook2function
(defun my-hook2 (guts opts state) (declare (xargs :mode :program :stobjs state)) (declare (ignore guts opts)) (value '(value-triple :invisible)))
other
(add-post-define-hook :foo my-hook)
other
(add-post-define-hook :bar my-hook2)
other
(assert! (equal (get-post-define-hooks-alist (w state)) '((:bar . my-hook2) (:foo . my-hook))))
other
(remove-post-define-hook :foo)
other
(add-post-define-hook :foo my-hook)
other
(assert! (equal (get-post-define-hooks-alist (w state)) '((:foo . my-hook) (:bar . my-hook2))))
other
(assert! (let ((guts (make-defguts :name 'myfun))) (equal (post-hook-make-events '(:foo (:bar 3) (:foo 5)) (get-post-define-hooks-alist (w state)) guts) `((make-event (my-hook ',STD::GUTS 'nil state)) (make-event (my-hook2 ',STD::GUTS '(3) state)) (make-event (my-hook ',STD::GUTS '(5) state))))))
other
(add-default-post-define-hook :bar)
other
(assert! (equal (get-default-post-define-hooks (w state)) '((:bar))))
other
(add-default-post-define-hook :foo 3)
other
(assert! (equal (get-default-post-define-hooks (w state)) '((:foo 3) (:bar))))
other
(remove-default-post-define-hook :bar)
other
(assert! (equal (get-default-post-define-hooks (w state)) '((:foo 3))))
other
(remove-default-post-define-hook :foo)
other
(remove-post-define-hook :foo)
other
(remove-post-define-hook :bar)
my-hook-1function
(defun my-hook-1 (guts opts state) (declare (xargs :mode :program :stobjs state)) (b* (((defguts guts) guts) (mksym-package-symbol guts.name) (- (cw "My-hook-1: Proving dumb theorem about ~x0.~%" guts.name)) ((unless (tuplep 1 opts)) (er soft 'my-hook-1 "Expected a single option (a hyp for the theorem), but got: ~x0." opts)) (hyp (first opts)) (event `(defthm ,(STD::MKSYM STD::GUTS.NAME 'STD::-SILLY-THM) (implies ,STD::HYP (equal (,STD::GUTS.NAME-FN . ,STD::GUTS.RAW-FORMALS) (,STD::GUTS.NAME-FN . ,STD::GUTS.RAW-FORMALS))) :rule-classes nil))) (value event)))
other
(add-post-define-hook :silly my-hook-1)
other
(define hooktest1 (x) :hooks ((:silly (consp a))) x :verbosep nil)
other
(encapsulate nil (set-enforce-redundancy t) (defthm hooktest1-silly-thm (implies (consp a) (equal (hooktest1 x) (hooktest1 x))) :rule-classes nil))
other
(define hooktest2 (x) :hooks ((:silly t)) x :verbosep nil)
other
(encapsulate nil (set-enforce-redundancy t) (defthm hooktest2-silly-thm (implies t (equal (hooktest2 x) (hooktest2 x))) :rule-classes nil))
other
(add-default-post-define-hook :silly (integerp b))
other
(define hooktest3 (x) x)
other
(encapsulate nil (set-enforce-redundancy t) (defthm hooktest3-silly-thm (implies (integerp b) (equal (hooktest3 x) (hooktest3 x))) :rule-classes nil))
other
(define hooktest4 (x) :hooks nil x)
other
(assert! (logical-namep 'hooktest3-silly-thm (w state)))
other
(assert! (not (logical-namep 'hooktest4-silly-thm (w state))))
other
(define my-make-alist (keys) :returns (alist alistp) (if (atom keys) nil (cons (cons (car keys) nil) (my-make-alist (cdr keys)))) /// (more-returns (alist true-listp :rule-classes :type-prescription) (alist (equal (len alist) (len keys)) :name len-of-my-make-alist)))
other
(include-book "std/lists/list-fix" :dir :system)
other
(more-returns my-make-alist (alist (equal (strip-cars alist) (list-fix keys)) :name strip-cars-of-my-make-alist))
other
(define my-make-alist-and-len (keys) :returns (mv (len natp :rule-classes :type-prescription) (alist alistp)) (b* (((when (atom keys)) (mv 0 nil)) ((mv cdr-len cdr-alist) (my-make-alist-and-len (cdr keys)))) (mv (+ 1 cdr-len) (cons (cons (car keys) nil) cdr-alist))) /// (more-returns (len (equal len (len keys)) :name my-make-alist-and-len.len-removal) (alist (integer-listp (strip-cars alist)) :hyp (integer-listp keys) :name integer-listp-strip-cars-my-make-alist-and-len) (alist true-listp :rule-classes :type-prescription)))
other
(remove-default-post-define-hook :silly)
other
(define inline-test (x) :inline t x)
other
(define notinline-test
(x)
:inline nil
x)
other
(assert! (equal (inline-test$inline 1) 1))
other
(assert! (equal (inline-test 1) 1))
other
(assert! (equal (notinline-test$notinline 2) 2))
other
(assert! (equal (notinline-test 2) 2))
other
(assert! (equal (untranslate-preproc-for-define '(inline-test$inline 1) (w state)) '(inline-test 1)))
other
(define nullary-inline-test nil :inline t nil)
other
(assert! (equal (untranslate-preproc-for-define '(nullary-inline-test$inline)
(w state))
'(nullary-inline-test)))
other
(defund ac-f (x) (- x 1))
other
(local (set-waterfall-parallelism nil))
other
(define ac-g1 (x) :verify-guards nil :t-proof t :hints (("Goal" :in-theory (enable ac-f))) (if (zp x) nil (ac-g1 (ac-f x))))
other
(assert-guard-unverified ac-g1)
other
(define ac-g2 (x) :verify-guards nil :t-proof t :verbosep t (declare (xargs :hints (("Goal" :in-theory (enable ac-f))))) (if (zp x) nil (ac-g2 (ac-f x))))
other
(assert-guard-unverified ac-g2)
other
(define another-guard-test-1 (x) (declare (type integer x)) x)
other
(define another-guard-test-2 ((x integerp)) x)
other
(define another-guard-test-3
((x :type integer))
x)
other
(define another-guard-test-4
(x)
(declare (xargs :guard (integerp x)))
x)
other
(define another-guard-test-5
(x state)
(declare (xargs :stobjs state))
(declare (ignorable state))
x)
other
(define another-guard-test-6 (x state) (declare (ignorable state)) x)
other
(assert-guard-verified another-guard-test-1)
other
(assert-guard-verified another-guard-test-2)
other
(assert-guard-verified another-guard-test-3)
other
(assert-guard-verified another-guard-test-4)
other
(assert-guard-verified another-guard-test-5)
other
(assert-guard-verified another-guard-test-6)
other
(define not-inline-and-no-function ((x natp)) :inline nil :returns (new-x natp :hyp :guard) (+ x 54))
other
(make-define-config :inline t :no-function nil :ruler-extenders (cons) :verify-guards :after-returns)