437
437
(defthm f-is-identity (equal (f x) x))))
439
439
(table spec-table 'i 10)))))
441
; Added by Matt K. This example responds to an observation from Bob Boyer,
442
; that it would be nice for there to be a general method of specifying notions
443
; like "bijection" to avoid errors in an ad hoc attempt to specify that a
444
; particular function is a bijection. I don't claim that this example is a
445
; anything like a complete solution to that problem -- in particular, it
446
; specifies bijection only for a function mapping pairs from a given domain --
447
; but I hope it suggests how one might develop a library of such "higher-order"
451
; Specify that a function bij2: dom2 x dom2 -> ran2 is a bijection.
459
(local (defun bij2 (x y) (cons x y)))
460
(local (defun inv1 (x) (car x)))
461
(local (defun inv2 (x) (cdr x)))
462
(local (defun dom2 (x) (declare (ignore x)) t))
463
(local (defun ran2 (x) (consp x)))
465
(implies (and (dom2 x1)
467
(ran2 (bij2 x1 x2))))
474
(defthm bij2-is-injective
475
(implies (and (dom2 x1)
484
(defthm bij2-is-surjective
486
(equal (bij2 (inv1 x) (inv2 x))
489
; Include Harsh's revised book.
491
(include-book "system/cantor-pairing-bijective" :dir :system)
493
; Separate out three key lemmas.
496
(implies (and (natp x1)
500
(equal (cantor-pairing x1 x2)
501
(cantor-pairing y1 y2)))
504
:use ((:instance cantor-pairing-one-one
505
(a1 x1) (b1 x2) (a2 y1) (b2 y2)))))
509
(implies (and (natp x1)
513
(equal (cantor-pairing x1 x2)
514
(cantor-pairing y1 y2)))
517
:use ((:instance cantor-pairing-one-one
518
(a1 x1) (b1 x2) (a2 y1) (b2 y2)))))
523
(equal (cantor-pairing (car (cantor-pairing-inverse x))
524
(cadr (cantor-pairing-inverse x)))
527
:use ((:instance cantor-pairing-onto
531
; Prove that cantor-pairing is a bijection.
533
(definstance bijection2 cantor-pairing-is-bijection
534
:functional-substitution
535
((bij2 cantor-pairing)
536
(inv1 (lambda (x) (car (cantor-pairing-inverse x))))
537
(inv2 (lambda (x) (cadr (cantor-pairing-inverse x))))
540
:hints (("Goal" :use (lemma1 lemma2 lemma3))))
542
; Finally, just for fun, show what was actually proved above. I would like to
543
; use (set-enforce-redundancy t) here. But unfortunately, one cannot use
544
; set-enforce-redundancy in a local context.
546
(defthm cantor-pairing-is-bijection
547
(and (implies (and (natp x1) (natp x2))
548
(natp (cantor-pairing x1 x2)))
550
(natp (car (cantor-pairing-inverse x))))
552
(natp (cadr (cantor-pairing-inverse x))))
553
(implies (and (natp x1)
557
(equal (cantor-pairing x1 x2)
558
(cantor-pairing y1 y2)))
559
(and (equal x1 y1) (equal x2 y2)))
561
(equal (cantor-pairing (car (cantor-pairing-inverse x))
562
(cadr (cantor-pairing-inverse x)))