From 33b3cd0dcabac33383f66bf5abb662443de5543a Mon Sep 17 00:00:00 2001
From: Robbert Krebbers <mail@robbertkrebbers.nl>
Date: Tue, 1 Jun 2021 17:27:08 +0200
Subject: [PATCH] Rename `Permutation_nil` and `Permutation_singleton` into
 `Permutation_nil_r` and `Permutation_singleton_r`.

Add lemmas `Permutation_nil_l` and `Permutation_singleton_l`.
---
 theories/fin_maps.v |  2 +-
 theories/fin_sets.v |  4 ++--
 theories/list.v     | 13 ++++++++++---
 theories/sorting.v  |  2 +-
 4 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/theories/fin_maps.v b/theories/fin_maps.v
index 45a0cc67..1d1dd5ca 100644
--- a/theories/fin_maps.v
+++ b/theories/fin_maps.v
@@ -938,7 +938,7 @@ Qed.
 Lemma map_to_list_singleton {A} i (x : A) :
   map_to_list ({[i:=x]} : M A) = [(i,x)].
 Proof.
-  apply Permutation_singleton. unfold singletonM, map_singleton.
+  apply Permutation_singleton_r. unfold singletonM, map_singleton.
   by rewrite map_to_list_insert, map_to_list_empty by eauto using lookup_empty.
 Qed.
 Lemma map_to_list_delete {A} (m : M A) i x :
diff --git a/theories/fin_sets.v b/theories/fin_sets.v
index 21b71cc6..a4581571 100644
--- a/theories/fin_sets.v
+++ b/theories/fin_sets.v
@@ -85,7 +85,7 @@ Qed.
 Lemma elements_empty' X : elements X = [] ↔ X ≡ ∅.
 Proof.
   split; intros HX; [by apply elements_empty_inv|].
-  by rewrite <-Permutation_nil, HX, elements_empty.
+  by rewrite <-Permutation_nil_r, HX, elements_empty.
 Qed.
 
 Lemma elements_union_singleton (X : C) x :
@@ -99,7 +99,7 @@ Proof.
 Qed.
 Lemma elements_singleton x : elements ({[ x ]} : C) = [x].
 Proof.
-  apply Permutation_singleton. by rewrite <-(right_id ∅ (∪) {[x]}),
+  apply Permutation_singleton_r. by rewrite <-(right_id ∅ (∪) {[x]}),
     elements_union_singleton, elements_empty by set_solver.
 Qed.
 Lemma elements_disj_union (X Y : C) :
diff --git a/theories/list.v b/theories/list.v
index deb74608..1f8f5ed0 100644
--- a/theories/list.v
+++ b/theories/list.v
@@ -1692,10 +1692,14 @@ Proof.
 Qed.
 
 (** ** Properties of the [Permutation] predicate *)
-Lemma Permutation_nil l : l ≡ₚ [] ↔ l = [].
+Lemma Permutation_nil_r l : l ≡ₚ [] ↔ l = [].
 Proof. split; [by intro; apply Permutation_nil | by intros ->]. Qed.
-Lemma Permutation_singleton l x : l ≡ₚ [x] ↔ l = [x].
+Lemma Permutation_singleton_r l x : l ≡ₚ [x] ↔ l = [x].
 Proof. split; [by intro; apply Permutation_length_1_inv | by intros ->]. Qed.
+Lemma Permutation_nil_l l : [] ≡ₚ l ↔ [] = l.
+Proof. by rewrite (symmetry_iff (≡ₚ)), Permutation_nil_r. Qed.
+Lemma Permutation_singleton_l l x : [x] ≡ₚ l ↔ [x] = l.
+Proof. by rewrite (symmetry_iff (≡ₚ)), Permutation_singleton_r. Qed.
 
 Lemma Permutation_skip x l l' : l ≡ₚ l' → x :: l ≡ₚ x :: l'.
 Proof. apply perm_skip. Qed.
@@ -1762,7 +1766,7 @@ Proof.
   - intros [k ->]. by left.
 Qed.
 
-Lemma Permutation_cons_inv l k x :
+Lemma Permutation_cons_inv_r l k x :
   k ≡ₚ x :: l → ∃ k1 k2, k = k1 ++ x :: k2 ∧ l ≡ₚ k1 ++ k2.
 Proof.
   intros Hk. assert (∃ i, k !! i = Some x) as [i Hi].
@@ -1772,6 +1776,9 @@ Proof.
   - rewrite <-delete_take_drop. apply (inj (x ::.)).
     by rewrite <-Hk, <-(delete_Permutation k) by done.
 Qed.
+Lemma Permutation_cons_inv_l l k x :
+  x :: l ≡ₚ k → ∃ k1 k2, k = k1 ++ x :: k2 ∧ l ≡ₚ k1 ++ k2.
+Proof. by intros ?%(symmetry_iff (≡ₚ))%Permutation_cons_inv_r. Qed.
 
 Lemma Permutation_cross_split l la lb lc ld :
   la ++ lb ≡ₚ l →
diff --git a/theories/sorting.v b/theories/sorting.v
index 3f019e54..afd9da0b 100644
--- a/theories/sorting.v
+++ b/theories/sorting.v
@@ -77,7 +77,7 @@ Section sorted.
     intros Hl1; revert l2. induction Hl1 as [|x1 l1 ? IH Hx1]; intros l2 Hl2 E.
     { symmetry. by apply Permutation_nil. }
     destruct Hl2 as [|x2 l2 ? Hx2].
-    { by apply Permutation_nil in E. }
+    { by apply Permutation_nil_r in E. }
     assert (x1 = x2); subst.
     { rewrite Forall_forall in Hx1, Hx2.
       assert (x2 ∈ x1 :: l1) as Hx2' by (by rewrite E; left).
-- 
GitLab