0

I need to proove that a secondary definition of permutation is equivalent to the default definition of permutation in Coq:

Down bellow is the default Permutation definition in Coq

Inductive Permutation : list A -> list A -> Prop :=
| perm_nil: Permutation [] []
| perm_skip x l l' : Permutation l l' -> Permutation (x::l) (x::l')
| perm_swap x y l : Permutation (y::x::l) (x::y::l)
| perm_trans l l' l'' :
    Permutation l l' -> Permutation l' l'' -> Permutation l l''.

I need to prove that the above mentioned definition is equivalent to the following definition:

Definition perm l l' := forall x, occurences_number x l = occurences_number x l'.

Which as you have noticed uses the definition occurences_number down bellow:

Fixpoint occurences_number x l := match l with
                       | nil => 0
                       | h::tl => if (x =? h) then S(occurences_number x tl) else occurences_number x tl
                       end.

What I need to prove indeed is the following:

Lemma permutation_to_perm: forall l l', Permutation l l' -> perm l l'.

Down bellow is my incomplete proof

Proof.
 induction l.
 - admit.
 - intros l' Hequiv.
   generalize dependent a.
   generalize dependent l.
   case l'.
   + Admitted.
Breno
  • 135
  • 8
  • It is probably easier to do induction on the hypothesis `Permutation l l'` instead of `l`. – Arthur Azevedo De Amorim Feb 11 '22 at 16:44
  • What do you mean @ArthurAzevedoDeAmorim? – Breno Feb 11 '22 at 16:45
  • In Coq, you can do induction not only on data structures, but also on hypotheses that state inductively defined propositions. If you are not familiar with this concept, I recommend having a look at the Software Foundations book: https://softwarefoundations.cis.upenn.edu/lf-current/IndProp.html#lab216. – Arthur Azevedo De Amorim Feb 11 '22 at 16:49
  • Ok, @ArthurAzevedoDeAmorim, What would you suggest me to go for the first subgoal after I stated `induction H`. – Breno Feb 11 '22 at 17:29

1 Answers1

1

Here is a proof that follows the strategy I outlined above:

Lemma Permutation_to_perm l l' : Permutation l l' -> perm l l'.
Proof.
intros H. induction H as [| x l1 l2 _ IH | x y l | l1 l2 l3 _ IH1 _ IH2 ].
- intros ?; reflexivity.
- intros y. simpl. now rewrite IH.
- intros z. simpl. now destruct (z =? y), (z =? x).
- intros ?. now rewrite IH1.
Qed.
Arthur Azevedo De Amorim
  • 23,012
  • 3
  • 33
  • 39
  • Please notice that the two approaches to permutation are equivalent when there exists a function to decide the equality between two elements of sequences (in you example, the type of elements is `nat`, but the same statement can be generalized to many other types). – Yves Feb 14 '22 at 07:34