1

This is the 5 star exercise from Software Foundations.

Lemma pumping : forall T (re : @reg_exp T) s,
  s =~ re ->
  pumping_constant re <= length s ->
  exists s1 s2 s3,
    s = s1 ++ s2 ++ s3 /\
    s2 <> [] /\
    forall m, s1 ++ napp m s2 ++ s3 =~ re.
Proof.
  intros T re s Hmatch.
  induction Hmatch
    as [ | x | s1 re1 s2 re2 Hmatch1 IH1 Hmatch2 IH2
       | s1 re1 re2 Hmatch IH | re1 s2 re2 Hmatch IH
       | re | s1 s2 re Hmatch1 IH1 Hmatch2 IH2 ]; simpl; intros.
  - omega.
  - omega.
  -
1 subgoal
T : Type
s1 : list T
re1 : reg_exp
s2 : list T
re2 : reg_exp
Hmatch1 : s1 =~ re1
Hmatch2 : s2 =~ re2
IH1 : pumping_constant re1 <= length s1 ->
      exists s2 s3 s4 : list T,
        s1 = s2 ++ s3 ++ s4 /\
        s3 <> [ ] /\ (forall m : nat, s2 ++ napp m s3 ++ s4 =~ re1)
IH2 : pumping_constant re2 <= length s2 ->
      exists s1 s3 s4 : list T,
        s2 = s1 ++ s3 ++ s4 /\
        s3 <> [ ] /\ (forall m : nat, s1 ++ napp m s3 ++ s4 =~ re2)
H : pumping_constant re1 + pumping_constant re2 <= length (s1 ++ s2)
______________________________________(1/1)
exists s0 s3 s4 : list T,
  s1 ++ s2 = s0 ++ s3 ++ s4 /\
  s3 <> [ ] /\ (forall m : nat, s0 ++ napp m s3 ++ s4 =~ App re1 re2)

I've spent too much time trying to split that H only to realize that despite day and a half work on this, many of my assumptions on how inequalities work turned out to be wrong. I had some great ideas last night which now that they've been discarded leave me more confused about this problem than ever. I've only been unlearning algebra in the past two days it seems.

I am going to be very embarrassed if the answer turns out to be that I need to match on the ss or length ss or pumping_constant res because I can't find a way to push through there.

The way this problem is set up highly suggests H should be split somehow in order to do the induction. I am still suspicious of it.

user4035
  • 22,508
  • 11
  • 59
  • 94
Marko Grdinić
  • 3,798
  • 3
  • 18
  • 21
  • 1
    I and the other Software Foundations authors kindly request you to refrain from discussing solutions to SF exercises in public forums. There are many courses that rely on these exercises to grade students. If you are having problems with this particular exercise, I suggest you look up a paper proof of the pumping lemma online and try to formalize it. – Arthur Azevedo De Amorim May 06 '19 at 18:12

1 Answers1

3

Yes, you need to split the H in order to proceed.

Vague hint: Do Search (_ + _ <= _ + _). and look for a theorem that catches your eyes.

Hint:

Nat.add_le_cases: forall n m p q : nat, n + m <= p + q -> n <= p \/ m <= q

Bubbler
  • 940
  • 6
  • 15
  • Perfect answer. Yesterday I tried solving that split using `omega` and it failed, so I drew the conclusion that it was likely not possible. Last night I figured out how to do the proof directly using mutual recursion between `pumping` and a helper function in a way that would be total, but this is a significantly better way of doing it. – Marko Grdinić May 07 '19 at 06:21
  • No wait, I jumped the gun here. Now that I am looking into it I realize that I need to split it into `n + m <= p + q -> n <= p /\ m <= q` rather than what that function does. Since that is probably impossible instead I am going to have to go with the idea I had myself. – Marko Grdinić May 07 '19 at 08:48
  • Actually, you were right after all. I thought that both inductive cases would be needed, but it is possible to make the proof for the MApp branch with only one. – Marko Grdinić May 07 '19 at 11:21
  • 1
    @Marko, your statement `n + m <= p + q -> n <= p /\ m <= q` is not true. Simple counterexample: `1 + 0 <= 0 + 1 -> 1 <= 0 /\ 0 <= 1`. Both inductive hypotheses are needed in the end, but only one is used *per case*. – Bubbler May 07 '19 at 23:13