• Top
    • Documentation
    • Books
    • Recursion-and-induction
    • Boolean-reasoning
    • Debugging
    • Projects
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
      • Theories
      • Rule-classes
      • Proof-builder
      • Hons-and-memoization
      • Events
      • History
      • Parallelism
      • Programming
      • Start-here
        • Gentle-introduction-to-ACL2-programming
        • ACL2-tutorial
          • Introduction-to-the-theorem-prover
            • Logic-knowledge-taken-for-granted
            • Logic-knowledge-taken-for-granted-inductive-proof
            • Introduction-to-rewrite-rules-part-1
            • Introduction-to-key-checkpoints
            • Introduction-to-rewrite-rules-part-2
            • Logic-knowledge-taken-for-granted-propositional-calculus
            • Introduction-to-a-few-system-considerations
            • Introduction-to-the-database
            • Programming-knowledge-taken-for-granted
            • Logic-knowledge-taken-for-granted-rewriting
            • Introductory-challenge-problem-4-answer
            • Introduction-to-programming-in-ACL2-for-those-who-know-lisp
            • Introduction-to-hints
            • Dealing-with-key-combinations-of-function-symbols
            • Architecture-of-the-prover
            • Further-information-on-rewriting
            • Frequently-asked-questions-by-newcomers
            • Specific-kinds-of-formulas-as-rewrite-rules
            • Strong-rewrite-rules
            • Practice-formulating-strong-rules-3
            • Practice-formulating-strong-rules-1
            • Generalizing-key-checkpoints
            • Logic-knowledge-taken-for-granted-q1-answer
            • Practice-formulating-strong-rules-6
            • Example-inductions
            • Logic-knowledge-taken-for-granted-q2-answer
            • Logic-knowledge-taken-for-granted-rewriting-repeatedly
            • Introductory-challenge-problem-4
            • Equivalent-formulas-different-rewrite-rules
            • Post-induction-key-checkpoints
            • Special-cases-for-rewrite-rules
            • Example-induction-scheme-with-accumulators
            • Practice-formulating-strong-rules-5
            • Practice-formulating-strong-rules
            • Practice-formulating-strong-rules-2
            • Introductory-challenges
            • Logic-knowledge-taken-for-granted-equals-for-equals
            • Logic-knowledge-taken-for-granted-evaluation
            • Example-induction-scheme-nat-recursion
            • Example-induction-scheme-down-by-2
            • Logic-knowledge-taken-for-granted-instance
            • Introductory-challenge-problem-3-answer
              • Example-induction-scheme-on-lists
              • Example-induction-scheme-upwards
              • Example-induction-scheme-with-multiple-induction-steps
              • Practice-formulating-strong-rules-4
              • Logic-knowledge-taken-for-granted-q3-answer
              • Example-induction-scheme-binary-trees
              • Introductory-challenge-problem-3
              • Introductory-challenge-problem-1
              • Logic-knowledge-taken-for-granted-base-case
              • Introductory-challenge-problem-1-answer
              • Example-induction-scheme-on-several-variables
              • Introductory-challenge-problem-2-answer
              • Introductory-challenge-problem-2
            • Pages Written Especially for the Tours
            • The-method
            • Advanced-features
            • Interesting-applications
            • Tips
            • Alternative-introduction
            • Tidbits
            • Annotated-ACL2-scripts
            • Startup
            • ACL2-as-standalone-program
            • ACL2-sedan
            • Talks
            • Nqthm-to-ACL2
            • Emacs
          • About-ACL2
        • Real
        • Debugging
        • Miscellaneous
        • Output-controls
        • Macros
        • Interfacing-tools
      • Interfacing-tools
      • Hardware-verification
      • Software-verification
      • Testing-utilities
      • Math
    • Introduction-to-the-theorem-prover

    Introductory-challenge-problem-3-answer

    Answer to challenge problem 3 for the new user of ACL2

    This answer is in the form of a script sufficient to lead ACL2 to a proof.

    ; Trying dupsp-rev at this point produces the key checkpoint: 
     
    ; (IMPLIES (AND (CONSP X) 
    ;               (NOT (MEMBER (CAR X) (CDR X))) 
    ;               (EQUAL (DUPSP (REV (CDR X))) 
    ;                      (DUPSP (CDR X)))) 
    ;          (EQUAL (DUPSP (APPEND (REV (CDR X)) (LIST (CAR X)))) 
    ;                 (DUPSP (CDR X)))) 
     
    ; which suggests the lemma 
     
    ; (defthm dupsp-append 
    ;   (implies (not (member e x)) 
    ;            (equal (dupsp (append x (list e))) 
    ;                   (dupsp x)))) 
     
    ; However, attempting to prove that, produces a key checkpoint 
    ; containing (MEMBER (CAR X) (APPEND (CDR X) (LIST E))). 
    ; So we prove the lemma: 
     
    (defthm member-append 
      (iff (member e (append a b)) 
           (or (member e a) 
               (member e b)))) 
     
    ; Note that we had to use iff instead of equal since 
    ; member is not a Boolean function. 
     
    ; Having proved this lemma, we return to dupsp-append and succeed: 
     
    (defthm dupsp-append 
      (implies (not (member e x)) 
               (equal (dupsp (append x (list e))) 
                      (dupsp x)))) 
     
    ; So now we return to dups-rev, expecting success.  But it fails 
    ; with the same key checkpoint: 
     
    ; (IMPLIES (AND (CONSP X) 
    ;               (NOT (MEMBER (CAR X) (CDR X))) 
    ;               (EQUAL (DUPSP (REV (CDR X))) 
    ;                      (DUPSP (CDR X)))) 
    ;          (EQUAL (DUPSP (APPEND (REV (CDR X)) (LIST (CAR X)))) 
    ;                 (DUPSP (CDR X)))) 
     
    ; Why wasn't our dupsp-append lemma applied?  We have two choices here: 
    ; (1) Think.  (2) Use tools. 
     
    ; Think: When an enabled rewrite rule doesn't fire even though the 
    ; left-hand side matches the target, the hypothesis couldn't be 
    ; relieved.  The dups-append rule has the hypothesis (not
    ; (member e x)) and after the match with the left-hand side, e 
    ; is (CAR X) and x is (REV (CDR X)).  So the system 
    ; couldn't rewrite (NOT (MEMBER (CAR X) (REV (CDR X)))) to true, 
    ; even though it knows that (NOT (MEMBER (CAR X) (CDR X))) from 
    ; the second hypothesis of the checkpoint.  Obviously, we need to 
    ; prove member-rev below. 
     
    ; Use tools:  We could enable the ``break rewrite'' facility, with 
     
    ; ACL2 !>:brr t 
     
    ; and then install an unconditional monitor on the rewrite rule 
    ; dupsp-append, whose rune is (:REWRITE DUPSP-APPEND), with: 
     
    ; :monitor (:rewrite dupsp-append) t 
     
    ; Then we could re-try our main theorem, dupsp-rev.  At the resulting 
    ; interactive break we type :eval to evaluate the attempt to relieve the 
    ; hypotheses of the rule. 
     
    ; (1 Breaking (:REWRITE DUPSP-APPEND) on 
    ; (DUPSP (BINARY-APPEND (REV #) (CONS # #))): 
    ; 1 ACL2 >:eval 
     
    ; 1x (:REWRITE DUPSP-APPEND) failed because :HYP 1 rewrote to 
    ; (NOT (MEMBER (CAR X) (REV #))). 
     
    ; Note that the report above shows that hypothesis 1 of the rule 
    ; did not rewrite to T but instead rewrote to an expression 
    ; involving (member ... (rev ...)).  Thus, we're led to the 
    ; same conclusion that Thinking produced.  To get out of the 
    ; interactive break we type: 
     
    ; 1 ACL2 >:a! 
    ; Abort to ACL2 top-level 
     
    ; and then turn off the break rewrite tool since we won't need it 
    ; again right now, with: 
     
    ; ACL2 !>:brr nil 
     
    ; In either case, by thinking or using tools, we decide to prove: 
     
    (defthm member-rev 
      (iff (member e (rev x)) 
           (member e x))) 
     
    ; which succeeds.  Now when we try to prove dups-rev, it succeeds. 
     
    (defthm dupsp-rev 
      (equal (dupsp (rev x)) 
             (dupsp x))) 
     
    

    Use your browser's Back Button now to return to introductory-challenge-problem-3.