0

I want to assert some lemmas at the top of the proof and re-use them for every future goal. I did:

  Theorem add_comm_eauto_using:
    forall n m: nat,
      n + m = m + n.
    Proof.
      intros. induction n.
      assert (H: forall n, n + 0 = n) by eauto using n_plus_zero_eq_n.
      assert (H': forall n m, S (n + m) = n + S m) by eauto using Sn_plus_m_eq_n_plus_Sm.
      - eauto with *.

but after I prove the base case the hypothesis dispear from the local context!

Why does that happen and how to I stop coq removing my local lemmas and keeping them in the local context in this proof forever? Ideally inside the Proof. body Qed. body.


script:


  Theorem n_plus_zero_eq_n:
  forall n:nat,
    n + 0 = n.
  Proof.
    intros.
    induction n as [| n' IH].
    - simpl. reflexivity.
    - simpl. rewrite -> IH. reflexivity.
  Qed.

  Theorem Sn_plus_m_eq_n_plus_Sm:
  forall n m : nat,
    S (n + m) = n + (S m).
  Proof.
    intros n m.
    induction n as [| n' IH].
    - auto.
    - simpl. rewrite <- IH. reflexivity.  
  Qed.

  Theorem add_comm :
  forall n m : nat,
    n + m = m + n.
  Proof.
    intros.
    induction n as [| n' IH].
    - simpl. rewrite -> n_plus_zero_eq_n. reflexivity.
    - simpl. rewrite -> IH. rewrite -> Sn_plus_m_eq_n_plus_Sm. reflexivity. 
  Qed.

  (* auto using proof *)
  Theorem add_comm_eauto_using_auto_with_start:
  forall n m: nat,
    n + m = m + n.
  Proof.
    intros. induction n.
    Print Hint.
      - auto with *.
      - auto with *. 
    Qed.

  Theorem add_comm_eauto_using:
    forall n m: nat,
      n + m = m + n.
    Proof.
      intros. induction n.
      assert (H: forall n, n + 0 = n) by eauto using n_plus_zero_eq_n.
      assert (H': forall n m, S (n + m) = n + S m) by eauto using Sn_plus_m_eq_n_plus_Sm.
      - eauto with *.
      - eauto using IHn, H, H'. 

Charlie Parker
  • 5,884
  • 57
  • 198
  • 323

1 Answers1

4

You define your lemmas in the part of the proof that is the base case; they are thus discarded when this step is completed. If you put them before the induction n, they will be accessible in both cases.

Pierre Jouvelot
  • 901
  • 3
  • 13
  • I've not open the `-` why does it define my lemmas there then? – Charlie Parker Mar 10 '22 at 22:28
  • The `induction` tactic opens the 2 cases. The `-` is, in SSReflect and to my knowledge, just a cosmetic sign to help structure the proof. You can also use `+`or `*` for that. – Pierre Jouvelot Mar 11 '22 at 06:28
  • Don't know whether it's an heresy, but I use the option `Set Bullet Behavior "Strict Subproofs"` when writing SSreflect proof scripts. – Pierre Castéran Mar 11 '22 at 06:43
  • @PierreCastéran : It is not an heresy. But among users of ssreflect, the [mathematical components library](https://math-comp.github.io) recommends a style different from what this option enforces. – Yves Mar 11 '22 at 07:18