235
235
:exec (if (hons-get a alist) t nil)))
238
(define all-equalp (a x)
240
:short "@(call all-equalp) determines if every members of @('x') is equal to
243
:long "<p>In the logic, we define @('all-equalp') in terms of
246
<p>We usually leave this enabled and prefer to reason about @('replicate')
247
instead. On the other hand, we also sometimes disable it and reason about it
248
recursively, so we do prove a few theorems about it.</p>
250
<p>For better execution speed, we use a recursive definition that does no
255
(equal (list-fix x) (replicate (len x) a))
258
(and (equal a (car x))
259
(all-equalp a (cdr x)))
262
:guard-hints(("Goal" :in-theory (enable all-equalp replicate)))
265
(defrule all-equalp-when-atom
269
(defrule all-equalp-of-cons
270
(equal (all-equalp a (cons b x))
275
(local (in-theory (disable all-equalp)))
277
(defrule car-when-all-equalp
278
(implies (all-equalp a x)
280
(if (consp x) a nil))))
282
(defrule all-equalp-of-cdr-when-all-equalp
283
(implies (all-equalp a x)
284
(all-equalp a (cdr x))))
286
(defrule all-equalp-of-append
287
(equal (all-equalp a (append x y))
288
(and (all-equalp a x)
292
(defrule all-equalp-of-rev
293
(equal (all-equalp a (rev x))
297
(defrule all-equalp-of-replicate
298
(equal (all-equalp a (replicate n b))
303
(defrule all-equalp-of-take
304
(implies (all-equalp a x)
305
(equal (all-equalp a (take n x))
307
(<= (nfix n) (len x)))))
308
:enable acl2::take-redefinition)
310
(defrule all-equalp-of-nthcdr
311
(implies (all-equalp a x)
312
(all-equalp a (nthcdr n x)))
315
(defrule member-equal-when-all-equalp
316
(implies (all-equalp a x)
317
(iff (member-equal b x)
324
239
(define remove-equal-without-guard (a x)
325
240
:parents (utilities)
914
(defsection keys-boundp
916
:short "@(call keys-boundp) determines if every key in @('keys') is bound in
917
the alist @('alist')."
919
(defund keys-boundp-fal (keys alist)
920
(declare (xargs :guard t))
923
(and (hons-get (car keys) alist)
924
(keys-boundp-fal (cdr keys) alist))))
926
(defund keys-boundp-slow-alist (keys alist)
927
(declare (xargs :guard t))
930
(and (hons-assoc-equal (car keys) alist)
931
(keys-boundp-slow-alist (cdr keys) alist))))
933
(defund keys-boundp (keys alist)
934
(declare (xargs :guard t :verify-guards nil))
938
(and (hons-assoc-equal (car keys) alist)
939
(keys-boundp (cdr keys) alist)))
943
(if (and (acl2::worth-hashing keys)
944
(acl2::worth-hashing alist))
945
(with-fast-alist alist (keys-boundp-fal keys alist))
946
(keys-boundp-slow-alist keys alist)))))
948
(local (in-theory (enable keys-boundp
950
keys-boundp-slow-alist)))
952
(defrule keys-boundp-fal-removal
953
(equal (keys-boundp-fal keys alist)
954
(keys-boundp keys alist)))
956
(defrule keys-boundp-slow-alist-removal
957
(equal (keys-boundp-slow-alist keys alist)
958
(keys-boundp keys alist)))
960
(verify-guards keys-boundp)
962
(defrule keys-boundp-when-atom
964
(equal (keys-boundp keys alist)
967
(defrule keys-boundp-of-cons
968
(equal (keys-boundp (cons a keys) alist)
969
(and (hons-get a alist)
970
(keys-boundp keys alist))))
972
(defrule keys-boundp-of-list-fix
973
(equal (keys-boundp (list-fix x) alist)
974
(keys-boundp x alist)))
976
(defrule keys-boundp-of-append
977
(equal (keys-boundp (append x y) alist)
978
(and (keys-boundp x alist)
979
(keys-boundp y alist))))
981
(defrule keys-boundp-of-rev
982
(equal (keys-boundp (rev x) alist)
983
(keys-boundp x alist)))
985
(defrule keys-boundp-of-revappend
986
(equal (keys-boundp (revappend x y) alist)
987
(and (keys-boundp x alist)
988
(keys-boundp y alist)))))
991
(defsection impossible
993
:short "Prove that some case is unreachable using @(see guard)s."
995
:long "<p>Logically, @('(impossible)') just returns @('nil').</p>
997
<p>But @('impossible') has a guard of @('nil'), so whenever you use it in a
998
function, you will be obliged to prove that it cannot be executed when the
1001
<p>What good is this? One use is to make sure that every possible case in a
1002
sum type has been covered. For instance, you can write:</p>
1005
(define f ((x whatever-p))
1007
(:foo (handle-foo ...))
1008
(:bar (handle-bar ...))
1009
(otherwise (impossible))))
1012
<p>This is a nice style in that, if we later extend @('x') so that its type can
1013
also be @(':baz'), then the guard verification will fail and remind us that we
1014
need to extend @('f') to handle @(':baz') types as well.</p>
1016
<p>If somehow @('(impossible)') is ever executed (e.g., due to program mode
1017
code that is violating guards), it just causes a hard error.</p>"
1019
(defun impossible ()
1020
(declare (xargs :guard nil))
1021
(er hard 'impossible "Provably impossible")))
1024
808
;; kind of a terrible function name
1025
809
(define vl-width-from-difference ((a integerp))
1026
810
:returns (width posp :rule-classes :type-prescription)